0

I am working with the R programming language. I am trying to follow the tutorial on "contour maps" posted over here: https://ggplot2.tidyverse.org/reference/geom_contour.html

I generated some data for this example:

#generate data
a <- rnorm(100,10,10)
b <- rnorm(100,5,5)
c <- rnorm(100,1,1)
d - data.frame(a,b,c)

Then, I tried to make these plots:

library(ggplot2)
v <- ggplot(d, aes(a, b, z = density))
v + geom_contour_filled()

But this produces the following warning messages:

Warning messages:
1: stat_contour(): Zero contours were generated 
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf

And produces an empty plot instead of the desired plot:

The Desired Plot

Can someone please show me what I am doing wrong?

Thanks

EDIT Potential Answer:

#avoid small margins error
dev.off()

#load library
library(akima)

#create plot

fld <- with(DF, interp(x = X1, y = X2, z = total))

filled.contour(x = fld$x,
               y = fld$y,
               z = fld$z,
               color.palette =
                   colorRampPalette(c("white", "blue")),
               xlab = "X1",
               ylab = "X2",
               main = "Contour Plot",
               key.title = title(main = "total ", cex.main = 1))

enter image description here

stats_noob
  • 3,127
  • 2
  • 8
  • 27
  • 1
    `geom_contour_filled` needs to have it's data on a regular grid. You need `n` x values and `m` y values. Note in the help page they use the `faithful` data which has `length(unique(faithfuld$eruptions))` and `length(unique(faithfuld$waiting))`. The x's and y's aren't just random. – MrFlick Jul 26 '21 at 03:51

0 Answers0