I´m struggling with assigning values to the linetype scale and have the legend rendered with different color and line for each of the keys. Using the (rather lengthy) command below I get
Error in col2rgb(colour, TRUE) : invalid color name 'GAM'
Any ideas what I´m doing wrong here?
..
Best,
//M
ggplot(b2,aes(as.numeric(bac),value))+facet_grid(GC~as2,scale="free_y")+geom_jitter(size=0.7,alpha=0.3,width=2)+geom_smooth(method="gam",formula=y~s(x),aes(colour="GAM",linetype="a"),size=0.5,se=F)+geom_smooth(method="lm",formula=y~x,aes(colour="OLS",linetype="p"),size=1)+scale_colour_manual("Method",c("OLS"="red","GAM"="blue"))+scale_linetype_manual("",c("a"=2,"p"=1))->z2
Could you please provide a reproducible example? (maybe with some
spaces and newlines too ;)
Hadley
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
ggplot(df, aes(gs, bac)) +
geom_point() +
geom_smooth(method = "gam", formula = y ~ s(x),
aes(colour = "GAM", linetype = "GAM"), se = F) +
geom_smooth(method = "lm", formula = y ~ x,
aes(colour = "OLS", linetype = "OLS"), se = F)
but this does not
ggplot(df, aes(gs, bac)) +
geom_point() +
geom_smooth(method = "gam", formula = y ~ s(x),
aes(colour = "GAM", linetype = "a"), se = F) +
geom_smooth(method = "lm", formula = y ~ x,
aes(colour = "OLS", linetype = "b"), se = F)
Hadley
> ggplot(df, aes(gs, bac)) +
> geom_point() +
> geom_smooth(method = "gam", formula = y ~ s(x),
> aes(colour = "GAM", linetype = "GAM"), se = F) +
> geom_smooth(method = "lm", formula = y ~ x,
> aes(colour = "OLS", linetype = "OLS"), se = F)
However I´d like to specify the linetype with the scale_linetype_manual command (mainly just to understand how scales can be put to use in the future)
scale_colour_manual("Method ",c("OLS"="red","GAM"="blue"))+scale_linetype_manual("",c("OLS"=2,"GAM"=1))
gives
Error in col2rgb(colour, TRUE) : invalid color name 'GAM'
Best
//M
n<-1000
b4<-data.frame(gc=factor(sample(1:5,n,replace=T)),as2=factor(sample(1:5,n,replace=T)),gs=sample(3:15,n,replace=T),bac=abs(rnorm(n)))
ggplot(b4,aes(bac,gs))+facet_grid(gc~as2,scale="free_y")->b5
##focus on linetype works well
b5<-b5+geom_jitter(size=0.7,alpha=0.3,width=2)
b5<-b5+geom_smooth(method="gam",formula=y~s(x ),aes(linetype="GAM"),se=F,color="red")
b5<-b5+geom_smooth(method="lm",formula=y~x,aes(linetype="OLS"),color="blue")
b5+scale_linetype_manual("",c("OLS"=2,"GAM"=1))
##focus on color works well
b5<-b5+geom_jitter(size=0.7,alpha=0.3,width=2)
b5<-b5+geom_smooth(method="gam",formula=y~s(x ),aes(colour="GAM"),se=F,linetype=1)
b5<-b5+geom_smooth(method="lm",formula=y~x,aes(colour="OLS"),linetype=2)
b5+scale_colour_manual("",c("OLS"="blue","GAM"="red"))
##but two different manual scales dont work
b5+geom_jitter(size=0.7,alpha=0.3,width=2)
b5<-b5+geom_smooth(method="gam",formula=y~s(x ),aes(colour="GAM",linetype="GAM",size="GAM")se=F)
b5<-b5+geom_smooth(method="lm",formula=y~x,aes(colour="OLS",linetype="OLS",size="OLS"))
b5
#OK, but not able to set my preferences
b5+scale_colour_manual("Method ",c("OLS"="red","GAM"="blue"))+scale_linetype_manual("",c("OLS"=2,"GAM"=1))
doesnt work and returns
Error in col2rgb(colour, TRUE) : invalid color name 'GAM'
Does anyone else manage to incorporate more than one manual scale in a plot? I´ve tried with other manual scales as well but with errors...
Best,
//M
On 29. juni 2010, at 23.26, Hadley Wickham wrote:
HAdley