Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple layers in ggplot2 with different datasets

Tags:

r

ggplot2

I have a contour plot and I would like to add a geom_path with a different set of data over it.

Right now I have the below code, but as soon as it gets to the geom_path, it overwrites the contour plot. Is there a way to prevent this from happening?

v <- ggplot(pts, aes(theta_1, theta_2, z = z))
v + stat_contour(aes(colour = ..level..),bins=50) + xlab(expression(Theta[1])) + ylab(expression(Theta[2]))
v+geom_path(aes(x=x,y=y,z=z), data=some.mat)
like image 508
Harold Avatar asked Feb 26 '23 23:02

Harold


1 Answers

probably you can do by:

v <- ggplot(pts, aes(theta_1, theta_2, z = z))
v <- v + stat_contour(aes(colour = ..level..),bins=50) + xlab(expression(Theta[1])) + ylab(expression(Theta[2]))
v + geom_path(aes(x=x,y=y,z=z), data=some.mat)
like image 172
kohske Avatar answered Feb 28 '23 12:02

kohske