I'm trying to create a contour plot for a very specific function. The contour plot I've obtained through ggplot2 is quite similar to Wolfram Alpha's plot, although I'm not getting the same "grid-like" (white stripes) behavior as in the latter source.
How could I get similar white stripes like those if I'm not sure what those values are? Should I increase the amount of points? I'm wondering if this is a finite precision problem and if there's a way to get past that.
Here goes an example of the plot I am expecting:
This is my code so far:
library(tidyverse)
v <- function(r, q){
value <- pmax(0, 3 * q - 1 + r - 3*r*q)^2 +
pmax(0, r - 3 * r * q)^2 +
pmax(0, -2 + 2*r + 2*q - 2*r*q)^2+
pmax(0, 2*q - 3*r*q)^2
return(value)
}
r <- q <- seq(0, 1, 0.001)
vertices <- expand_grid(r, q)
vertices %>% mutate(v = v(r, q)) %>%
ggplot(aes(x = r, y = q, z = v)) +
geom_contour_filled()