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
View all comments
Show parent comment
2
u/[deleted] Jan 26 '18
So what we do is pretty much we "factor something" by its categorial variable (say, for instance, "horsepower as a group" - each with the same horsepower is displayed by one line.
If that is true, how is that line made? I mean, even though you may group statistical units that have a common realisation of a variable , they may differ in other variables. How is that line made? Is the mean calculated for (here wt and mpg) ?
Also, how does group = 1 work? Is the first categorial variable in the data frame referred to by 1?