Do you want something like:
p <- ggplot(xx, aes(x = 0, xend = Expense,  y = Food, yend = Food))
pa <- p + geom_point(aes(Expense, Food)) +
       geom_segment(colour=c("red","blue","purple","darkgreen")) +
       xlab("Food") + geom_vline(xintercept=40, colour='red')
pa

----- Original Message ----- From: "John Kane" <jrkrid...@yahoo.ca>
To: <r-h...@stat.math.ethz.ch>
Sent: Monday, August 10, 2009 2:29 PM
Subject: [R] ggplot: colours to geom_segments



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

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to