Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot a point in a contour plot ggplot2

Tags:

r

ggplot2

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

My contour plot looks like this:

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 overwrites the first.

Is there a way to get them to show up on the same plot, similar to MATLAB's "hold on;"?

Thanks!

like image 405
Harold Avatar asked Oct 19 '10 04:10

Harold


1 Answers

You can provide the points directly to geom_point():

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

like image 135
Greg Avatar answered Nov 04 '22 05:11

Greg