[R] ggplot: colours to geom_segments
John Kane
jrkrideau at yahoo.ca
Mon Aug 10 21:29:52 CEST 2009
Just as an exercise I am tying to add colours to a geom_segment command. I can get one colour but not a sequence of colours.
Can anyone suggest how I can get the green lines in the plot below to be different colours? I thought I could use a palatte of colours but that did not seem to work.
Thanks
=========================================================================
library(ggplot2)
xx <- structure(list(Food = structure(c(2L, 1L, 3L, 4L), .Label = c("Bread",
"Milk", "Potatoes", "Rice"), class = "factor"), Expense = c(25,
49, 34, 15)), .Names = c("Food", "Expense"), row.names = c(NA,
-4L), class = "data.frame")
p <- ggplot(xx, aes(x = 0, xend = Expense, y = Food, yend = Food))
pa <- p + geom_point(aes(Expense, Food)) +
geom_segment(colour="darkgreen") +
xlab("Food") + geom_vline(xintercept=40, colour='red')
pa
More information about the R-help
mailing list