How to add color aesthetic to geom_line stat layer

80 views
Skip to first unread message

Art

unread,
May 3, 2014, 6:35:22 PM5/3/14
to ggp...@googlegroups.com
Hello all,

I'm trying to plot the mean for each group using the same colors as the points.

This is my plot code.

How do I change geom_line so that the lines are the same as the group colors?

test <- ggplot(aes(x = x, y = y, group = group), data = data) +
  geom_point(aes(colour = group)) +
  geom_line(stat = 'summary', fun.y = mean)


Thanks!

Art

unread,
May 3, 2014, 6:41:27 PM5/3/14
to ggp...@googlegroups.com
Sorry, I figured it out.

test <- ggplot(aes(x = x, y = y, group = group), data = data) +
  geom_point(aes(colour = group)) +
  geom_line(stat = 'summary', fun.y = mean, aes(colour = group)

Dennis Murphy

unread,
May 3, 2014, 6:41:34 PM5/3/14
to Art, ggplot2
Try

test <- ggplot(aes(x = x, y = y, group = group, colour = group), data = data) +
geom_point() +
geom_line(stat = 'summary', fun.y = mean)

Aesthetics defined in the ggplot() statement apply to all layers.
Defining aesthetics inside a geom() call make them local to the layer
in which they are defined.

Dennis
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages