I'd like to add a point to an existing filled.contour
plot, using the following code:
MyFunction <- function(x,y){
return(dnorm(sqrt(x^2+y^2)))
}
wrapper <- function(x, y, my.fun, ...) {sapply(seq_along(x), FUN = function(i) my.fun(x[i], y[i], ...))}
meshstep <- 0.5
x<- seq(-20,20,meshstep)
y <-seq(-20,20,meshstep)
z <- outer(x,y,FUN = wrapper, my.fun=MyFunction)
filled.contour(x,y,z, col=rev(heat.colors(n=20, alpha=0.7)), nlevels=15)
points(0,0)
I'm pretty surprised that points(0,0)
didn't put a point into the origin of the plot, but roughly located at x=10,y=0. Also, locator()
seems to be prompting coordinates with respect to that 'new' coordinate system as well. Why is that?
Rather than having discrete contour lines, “filled” contour plots shade the regions between contours according to a colormap. Contour lines themselves are not plotted. Use Contour Plot in combination with this VI to display lines.
You can find a detailed answer here : Plotting a box within filled.contour plots in R?
In short, filled.contour
use two different coordinates system, one for the filled contour and one for the legend. To solve your problem, you either have to use another function, or to put your points
into the plot.axes
argument :
filled.contour(x,y,z, col=rev(heat.colors(n=20, alpha=0.7)), nlevels=15,
plot.axes={points(0,0)})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With