Reputation: 1162
I have the following data
df = data.frame(names = c(rep('var1',time=6),rep('var2',time=6)),
dat = rnorm(n=12,sd=1:3),
type=c(rep(c('mod1','mod2','mod3'),time=2)),
length=c('1','1','2','1','3','3'))
I want a different colour for each type and different symbols for each length, which can be done using ggplot2:
ggplot(df,aes(x=names,y=dat,pch=length,colour=type)) +
geom_point()
However, I would like them to be "dodged" by colour/type but not by pch/length, which is what happens if I do this
ggplot(df,aes(x=names,y=dat,pch=length,colour=type)) +
geom_point(position=position_dodge(width=0.6))
I can't find a command that would allow me to specify that the position_dodge should only apply to the colour but not pch. Any tips?
Upvotes: 1
Views: 250
Reputation: 15441
I think this is what you want...
ggplot(df,aes(x=names,y=dat,group=type)) +
geom_point(aes(colour=type,pch=length),position=position_dodge(width=0.6))
using your df
gives:
Upvotes: 1