[R] change colour of geom_step by scale_colour_manual

Brian Diggs diggsb at ohsu.edu
Mon Nov 12 23:08:08 CET 2012


On 11/6/2012 11:11 PM, ChangLH wrote:
> Hi,
> Color of my step plot is now by default. Now I'd like to change the color as
> the grey scale I specified. I don't know why I got three black plot. Here I
> attach two version of codes. The first one produces a step plot with color
> by default. The second one, modified from the first one, is not producing
> the grey scale I want. Any help would be highly appreciated.
>
> [version 1- working]
> library(ggplot2)
> ggplot(qry_r3_AFF0_CumRate_pooled[qry_r3_AFF0_CumRate_pooled$trt_label %in%
> c('ace','ctrlAM','met'),]
>         , aes(x=AFF0, y=cum_rate_AFF0_pooled, group=trt_label))+
>           geom_step(aes(color=trt_label), direction="hv", size=5.0)+
>           scale_y_continuous("Rates of initiating first orientation flight",
> limits=c(0,0.6), expand=c(0,0), breaks=c(0,0.2,0.4,0.6)) +
>           scale_x_continuous("Age of adults (days)", limits=c(0,16),
> expand=c(0,0), breaks=c(5, 10, 15)) +
>           scale_colour_discrete(name  ="Group",
>                                 breaks=c("ace", "ctrlAM","met"),
>                                 labels=c("acetone",
> "untreated","methoprene"))+
>                                   theme_bw() +   # maek background theme
> black and white
>                                   opts(legend.justification=c(1,0),# legend
> justification needs to be in the (options)
>                                        legend.position=c(1,0),
>                                        panel.grid.major = theme_line(size =
> 0.5, colour = '#FFFFFF'),
>                                        panel.grid.minor = theme_line(colour =
> NA) # colour = NA to suppress gridlines, reappear if colour='black'
>                                  )
>
> <http://r.789695.n4.nabble.com/file/n4648669/step_plot_in_default_color.png>
>
> [version 2- producing wrong colour]
> #try greyScale, didn't work
> all <-qry_r3_AFF0_CumRate_pooled
> all <- subset(all, trt_label %in% c('ace','ctrlAM','met'))
> greyScale <-c("grey15","grey30","grey45")
>
> ggplot(all, aes(x=AFF0, y=cum_rate_AFF0_pooled, group=trt_label))+
>        geom_step(direction="hv", size=3.0)+

Here, you got rid of the mapping of colour to trt_label that you had in 
the first example, so there is no colour to be manually mapped. That is 
why all three lines were black.

>        scale_y_continuous("Rates of initiating first orientation flight",
> limits=c(0,0.6), expand=c(0,0), breaks=c(0,0.2,0.4,0.6)) +
>        scale_x_continuous("Age of adults (days)", limits=c(0,16),
> expand=c(0,0), breaks=c(5, 10, 15)) +
>        scale_colour_manual(name="Group",
>                            breaks=c('ace', 'ctrlAM','met'),
>                            labels=c("acetone", "untreated","methoprene"),
>                            values=c("black","grey","red"))
>
>        theme_bw() +   # maek background theme black and white
>        theme(legend.justification=c(1,0),# legend justification needs to be
> in the (options)
>              legend.position=c(1,0),
>              panel.grid.major = theme_line(size = 0.5, colour = '#FFFFFF'),
>              panel.grid.minor = theme_line(colour = NA) # colour = NA to
> suppress gridlines, reappear if colour='black'
>              )
>
> <http://r.789695.n4.nabble.com/file/n4648669/step_plot_not_showing_grey_scale_colour.png>
>
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/change-colour-of-geom-step-by-scale-colour-manual-tp4648669.html
> Sent from the R help mailing list archive at Nabble.com.
>


-- 
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University




More information about the R-help mailing list