Contour plot equivalent to Wolfram Alpha's

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:
image

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

Hi @jclmntn,

sorry for asking a stupid question, but are you sure that you are using the same function in both cases?

If the white lines in your Wolfram Alpha plot are considered to have function value zero, I would also expect any function value v(r = 0, q) to be zero. However:

> v(r = 0, q = 0)
[1] 0
> v(r = 0, q = 1)
[1] 8
> v(r = 0, q = -1)
[1] 0
> v(r = 0, q = -0.5)
[1] 0
> v(r = 0, q = -2)
[1] 0
> v(r = 0, q = -3)
[1] 0
> v(r = 0, q = -5)
[1] 0
> v(r = 0, q = +2)
[1] 45

Furthermore, your value at (-1, -1) looks different from zero (red), but

> v(r = -1, q = -1)
[1] 0

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.