Closed
Description
I also submitted this via StackOverflow, since I wasn't 100% sure if the problem were user error or an actual problem with the code.
Successful Run
It's possible I do not understand the expectations, however, if I follow the example at stat_contour
's documentation, I successfully get:
# Generate data
library(reshape2) # for melt
volcano3d <- melt(volcano)
names(volcano3d) <- c("x", "y", "z")
# Basic plot
v <- ggplot(volcano3d, aes(x, y, z = z))
v + stat_contour()
leading to:
Unsuccessful Run
However, when I try to do what appears to be _exactly the same thing with exactly the same data types_, I have errors:
my_plt <- ggplot(diamonds, aes(depth, carat, z=price))
my_plt + stat_contour()
yields:
Warning message:
Computation failed in `stat_contour()`:
(list) object cannot be coerced to type 'double'
Debugging Attempt
The only potential difference I could imagine, especially with the error I was receiving, was an object type difference. So, here are some details there:
-
volcano3d
head(volcano3d) x y z 1 1 1 100 2 2 1 101 3 3 1 102 4 4 1 103 5 5 1 104 6 6 1 105
And...
volcano3d %>% sapply(class) x y z "integer" "integer" "numeric"
-
diamonds
diamonds %>% select(depth, carat, price) %>% head Source: local data frame [6 x 3] depth carat price (dbl) (dbl) (dbl) 1 61.5 0.23 326 2 59.8 0.21 326 3 56.9 0.23 327 4 62.4 0.29 334 5 63.3 0.31 335 6 62.8 0.24 336
And...
diamonds %>% select(depth, carat, price) %>% sapply(class) depth carat price "numeric" "numeric" "numeric"
I cannot see any reason why I should be getting these errors. Any ideas??
Thanks!