# sample Datad <-data.frame (Expand.grid (X=letters[1:4], G=factor (1:2)), Y=rnorm (8)) # Figure 1a, 1b, and 1c.ggplot (D, AES (X=x, Y=y, colour=g)) + opts (title= "Figure 1a") + geom_line () + geom_point () Ggplot (d, AES (X=x, Y=y, Colour=g, group=g)) + opts (title= "1b") + geom_line () + geom_point () Ggplot (d, AES (X=x, Y=y, Colour=g, group=1)) + opts (title= "Figure 1c ") + geom_line () + geom_point ()
The figure 1a does isn't draw any lines, while the figure of 1b works well.
The key concept is a "group" in AES.
The rule is simple:
- Geom_line () tries to connect data points this belong to same group.
- Different levels of factor variable belong to different group.
So, by specifying GROUP=G in AES, the lines appear in Figure 1b.
Figure 1c would help to understand more.
In Figure 1c, all data points belong to Group=1, hence all data points is connected.
REF:
http://www.markhneedham.com/blog/2015/01/30/ r-ggplot2-each-group-consist-of-only-one-observation-do-you-need-to-adjust-the-group-aesthetic/
Http://stackoverflow.com/questions/27082601/ggplot2-line-chart-gives-geom-path-each-group-consist-of-only-one-observation
https://kohske.wordpress.com/2010/12/27/faq-geom_line-doesnt-draw-lines/
Geom_path:each group consist of only one observation. Need to adjust the group aesthetic?