Merging 2 scatter plots or add data points to an existing scatter plot

3,946 views
Skip to first unread message

l.r...@gmx.us

unread,
Nov 11, 2013, 8:26:53 PM11/11/13
to ggp...@googlegroups.com
Hi,

I have a simple ggplot:
p1<-ggplot(datared, aes(x=axes1, y=axes2) ) + geom_point( size = 2, aes(color = group))

and another plot that contain the means of the groups

p2<-ggplot(dataredMeans, aes(x=meanaxes1, y= meanaxes 2)) + geom_point(shape = 4, size = 6,   aes(color = group)) + theme(legend.position="none")

How can I merge these plots or how can I add to p1 the p2 external points (dataredMeans) which are marked as X with bigger size?

Thanks a lot.

Doug Mitarotonda

unread,
Nov 12, 2013, 12:36:30 AM11/12/13
to l.r...@gmx.us, ggplot2
Hi,
You would just need to use the `data` argument of the geom to add the second layer.

So something like:

p1<-ggplot(datared, aes(x=axes1, y=axes2) ) + geom_point( size = 2, aes(color = group)) + theme(legend.position="none")
p2 <- p1 + geom_point(data = dataredMeans, shape = 4, size = 6, mapping = aes(x=meanaxes1, y= meanaxes2, color = group))

Best wishes,
Doug


--
--
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/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages