On 09/19/2020 12:42 AM, Jeff Newmiller wrote: > When dealing with a 2-d density plot, the z variable is a predefined function > of your x and y data, it is not something you can specify. If you want to > specify z, then you need to use geom_contour. You appear to need to study the > theory of kernel density estimates, which is off topic here. (Technically > contributed packages like ggplot2 are off topic here also, though sometimes > people will answer questions about them anyway.) > > On September 18, 2020 6:34:43 PM PDT, H <age...@meddatainc.com> wrote: >> On 09/18/2020 02:26 AM, Jeff Newmiller wrote: >>> No, but fortunately you are off in the weeds. Density has an >> internally-computed "z" coordinate... you should be looking at >> ?geom_contour. >>> On September 17, 2020 7:17:33 PM PDT, H <age...@meddatainc.com> >> wrote: >>>> I am trying to understand how to map 2D to 3D using ggplot() and >>>> eventually plot_gg(). I am, however, stuck on understanding how to >>>> express the third variable to be mapped. This example: >>>> >>>> ggdiamonds = ggplot(diamonds, aes(x, depth)) + >>>> stat_density_2d(aes(fill = stat(nlevel)), >>>> geom = "polygon", n = 100, bins = 10,contour = TRUE) + >>>> facet_wrap(clarity~.) + >>>> scale_fill_viridis_c(option = "A") >>>> >>>> uses a variable nlevel that I now understand is calculated during >> the >>>> building of the ggplot but I have not figured out from where it is >>>> calculated or how to specify a variable of my choosing. >>>> >>>> Does anyone have a good reference for understanding how to specify >> this >>>> variable? Most examples on the 'net seem to use the same dataset but >> do >>>> not specify this particular aspect... >>>> >>>> ______________________________________________ >>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>>> https://stat.ethz.ch/mailman/listinfo/r-help >>>> PLEASE do read the posting guide >>>> http://www.R-project.org/posting-guide.html >>>> and provide commented, minimal, self-contained, reproducible code. >> But looking at the code in my message above, how does one know what >> stat(nlevel) refers to? What if I wanted to map another variable in >> this particular dataset?? >> >> ______________________________________________ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code.
Understood, I just began looking at the volcano dataset which uses geom_contour. I now realize that the function stat_density_2d really maps a heatmap of a computed variable. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.