Geom_path:each group consist of only one observation. Need to adjust the group aesthetic?

Source: Internet
Author: User
Tags ggplot

# 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:

    1. Geom_line () tries to connect data points this belong to same group.
    2. 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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.