Set point in ggplot2 outline graph

I have a contour plot in ggplot2 that I want to map to a single point.

My outline graph is as follows:

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])) 

and I have a point that looks like this:

 p = ggplot(ts,aes(x,y)) p + geom_point() 

Unfortunately, the second one overwrites the first.

Is there a way to make them appear on the same plot, similar to MATLAB "hold on" ,?

Thanks!

+4
source share
2 answers

You can directly specify geom_point() points:

 set.seed(1000) x = rnorm(1000) g = ggplot(as.data.frame(x), aes(x = x)) g + stat_bin() + geom_point(data = data.frame(x = -1, y = 40), aes(x=x,y=y)) 

alt text

+6
source

Not sure if this is still interesting, but I think you just need to save the updated v-object and then add a point to it, and not create a new ggplot2 object. for instance

 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 <- v + geom_point(aes(x=ts$x, y=ts$y)) v # to display 

ggplot2 adds levels very well gradually, not all should be based on the same dataset that was specified in the first ggplot call.

0
source

All Articles