Can anybody help me to change colours in ggplot2?
Here is my example:
df0<-data.frame(x=rnorm(6),y=rnorm(6),grp=factor(rep(c("blue","green","purple"),each=2)))
ggplot(df0,aes(x=x,y=y,colour=grp)+geom_point+scale_colour_brewer(palette="Ste1")
But, the points colour are not like their name: group 'blue' is red;
group 'green' is blue; group 'purple' is green.
Because the colors in 'Set1' is : red, blue, green, purple, ......
so I decided to insert a new empty level into 'grp', to let them match
like this:
"empt" => red
"blue" => blue
"green"=> green
"purple"=>purple
I do like this:
df0$grp2<-factor(df0$grp,levels=c("empt",levels(df0$grp)))
ggplot(df0,aes(x=x,y=y,colour=grp2)+geom_point+scale_colour_brewer(palette="Ste1")
I thought that ggplot will assign red to level 'empt', assign blue to
level 'blue', etc.
but it doesn't work... The colour didn't change.
How can I do this?
Thanks!
Lan
Lan
--
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
I try again, with typo fixed, but still doesn't work.
The results from these two lines are the same in my screen:
ggplot(df0,aes(x=x,y=y,colour=grp2))+geom_point()+scale_colour_brewer(palette="Set1")
ggplot(df0,aes(x=x,y=y,colour=grp))+geom_point()+scale_colour_brewer(palette="Set1")
and I'm sure the two factors are different:
df0$grp
[1] blue blue green green purple purple
Levels: blue green purple
df0$grp2
[1] blue blue green green purple purple
Levels: empt blue green purple
And about the alternative solution, the problem is, I like some
colours in brewer, but I don't know their name.