r - ggplot2 graph and overriding -


i have started using ggplot2 so, once again apologize posting basic question.

i read code in 1 of pages. code nicely plots line graph , average red dot:

ggplot(mpg, aes(trans, cty)) +   geom_point() +   stat_summary(geom = "point", fun.y = "mean", colour = "red", size = 4) 

i thought of simplifying bit overriding contents of geom_point() , using stat="summary"

ggplot(mpg, aes(trans, cty)) +   geom_point(stat = "summary", fun.y = "mean", colour = "red", size = 4) +  

however, above code doesn't work. can please me why above code doesn't work? specifically, plots red dot (mean point). don't see scatterplot although have used geom_point()

because ggplot() defines aes(), overriding them using geom layer.

in first case, geom_point() completes plotting of points, , stat_summary() did part of adding summary statistics layer graph.

but, when define stat = "summary", tell geom_point() plot summary statistics instead of data points.

head on ggplot2 documentation , read how mapping works within ecosystem: http://docs.ggplot2.org/current/


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -