r/R_Programming • • Jan 26 '18

Ggplot2: group in aes()

Hello there,

currently trying to figure out how to work with ggplot2.

I'm stuck at Data Camp's second tutorial (2-2) on ggplot (just so anyone knows what I am dealing with).

Have this code snippet:

ggplot(mtcars, aes(x = wt, y = mpg, col = factor(cyl))) +
  geom_point() +
  stat_smooth(method = "lm", se = F, aes(group= 1))

What does group in aesthetic actually do? I know that method="lm" gives me a straight line and se=F removes the shading of the line (does the shading represent standard derivation?)

DC's ggplot 2-1 tutorial was easy but 2-2 is unclear as hell.

3 Upvotes

3 comments sorted by

View all comments

Show parent comment

1

u/Darwinmate Feb 02 '18

I think, but I can't find any documentation anywhere, that group=1 is actually overriding the grouping variable, so smooth line is proportion to all data. You will get the same effect if you use group="PENIS" or group=2

Here is where I found the answer: https://stackoverflow.com/questions/39878813/r-ggplot-geom-bar-meaning-of-aesgroup-1

BTW, group="PENIS" does give the same result as group=1. If you remove aes(group=1) you will see the result of the standard behaviour.