[R] specifying colours in a ggplot2 piechart
John Kane
jrkrideau at yahoo.ca
Tue Nov 23 19:47:00 CET 2010
Someone was asking how to do a 16 category piechart in OpenOffice Calc and it appears that it can not be done (which we, probably, should be happy about) but I thought that I'd try it in ggplot2.
It works but I then thought I'd like to make the colours more distinctive but fro some reason I don't seem to be able to use manually assigned colours.
Can anyone suggest where I'm going wrong?
Thanks
===================================================================
library(ggplot2)
mypie <- data.frame(xx = c(12,13,6,7,9,10,4, 3, 8, 6, 8, 4, 6,5,2,3),
zz = letters[1:16])
mycolours <- c(a = "red", b = "blue", c = "green", d = "orange", e = "red",
f = "blue", g = "geen", h = "orange", i = "red", j = "blue",
k = "green", l = "orange", m = "red", n = "blue", o = "green",
p = "orange" )
pie1 <- ggplot(mypie, aes(x = factor(zz), fill = factor(zz))) + geom_bar(width = 1)
pie2 <- pie + coord_polar(theta = "x") + scale_colour_brewer(Pastel1)
pie2
# try to get even nastier piechart with ugly colours to provide rast.
pie3 <- pie2 + scale_colour_manual(value=mycolours)
pie
More information about the R-help
mailing list