[R] colour input in geom line ggplote2
jdnewmil at dcn.davis.ca.us
Wed Dec 23 18:07:14 CET 2015
There is a problem built into your question: you are treating carb graphically as a continuous variable, yet by asking for a line plot of mean values you seem to be assuming it is discrete. Below are several possible interpretations of your intent.
p <- ggplot( mtcars, aes( x=carb, y=mpg ) ) + geom_point()
p + stat_summary( geom="ribbon", fun.ymin="min", fun.ymax="max" )
p2 <- p + stat_summary( geom="ribbon"
# local regression
p + geom_smooth()
# literal interpretation
p2 + geom_hline( yintercept = mean( mtcars$mpg ), colour="red" )
# linear regression
p2 + geom_smooth( method="lm", se=FALSE, colour="red" )
mtcarsmean <- aggregate( mtcars$mpg, mtcars[ , "carb", drop=FALSE ], mean )
# discrete means
p2 + geom_line( data=mtcarsmean, mapping=aes( x=carb, y=x ), colour="red" )
The reason this has to be done explicitly outside of the geom_smooth mechanism is because of this conflict between graphically continuous and conceptually discrete data.
Sent from my phone. Please excuse my brevity.
On December 22, 2015 11:43:23 PM PST, pushan chakraborty <pushan.zoology at gmail.com> wrote:
>I want to put a line command in the following and also want to
>colour in the geom line command line. It would be a ribbon plot showing
>mean line. Is there any help?
>p <- ggplot(mtcars, aes(x=carb, y=mpg)) + geom_point()
>p + stat_summary(geom="ribbon", fun.ymin="min", fun.ymax="max")
>p + stat_summary(geom="ribbon", fun.ymin="min", fun.ymax="max",
> alpha=0.2, fill="blue")
>CSIR - SRF
>Center for Pollination Studies, University of Calcutta
>35, Ballyguanje Circular Road, Kolkata - 700019
>Wildlife Institute of India
>Chandrabani, Dehradun - 248001
> [[alternative HTML version deleted]]
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help