Reputation: 779
I have two ggplots. Can I somehow paint them on one picture? One as a background of another My code :
ggplot(data = dd, aes(x = x, y = y)) +
+ geom_point(colour="red", size = 3, aes(alpha=col))
ggplot(data=df, aes(x=x, y=y)) + geom_segment(aes(xend=x+dx, yend=y+dy), arrow = arrow(length = unit(0.3,"cm")))
Thanks
Upvotes: 0
Views: 196
Reputation: 49033
With ggplot2 you can plot data from different sources by specifying a different data
argument to your different geom_*
. Something like :
library(grid)
df <- data.frame(x=runif(10),y=runif(10),dx=rnorm(10),dy=rnorm(10))
dd <- data.frame(x=runif(15), y=runif(15))
ggplot() +
geom_point(data=dd, aes(x=x, y=y), col="red") +
geom_segment(data=df, aes(x=x, y=y, xend=x+dx, yend=y+dy), arrow = arrow(length = unit(0.3,"cm")))
Is this what you are trying to do ?
Upvotes: 2