简体   繁体   中英

x-axis on joy plot shows incorrect values

I am new to making joy plots in R. Below is a plot I made with some simulated data. I'm confused though, because my data variable foo contains no negative values, but the resulting plot would indicate so:

library(ggjoy)

p <- ggplot(results, aes(foo, bar)) +  geom_joy()

The data is:

results <- structure(list(foo = c(462.834004209936, 460.834004209936, 73.0340042099357, 
106.134004209936, 165.634004209936, 200.134004209936, 490.434004209936, 
157.334004209936, 460.834004209936, 131.434004209936, 269.934004209936, 
457.534004209936, 459.634004209936, 475.534004209936, 180.034004209936, 
142.134004209936, 294.734004209936, 419.534004209936, 279.834004209936, 
280.734004209936, 448.034004209936, 206.334004209936, 283.134004209936, 
243.034004209936, 530.334004209936, 396.934004209936, 49.8340042099357, 
136.134004209936, 210.234004209936, 59.0340042099357, 269.834004209936, 
123.034004209936, 385.434004209936, 78.7340042099357, 226.434004209936, 
391.034004209936, 219.434004209936, 338.134004209936, 87.0340042099357, 
434.234004209936, 123.034004209936, 75.7340042099357, 247.234004209936, 
192.334004209936, 146.234004209936, 259.334004209936, 72.5340042099357, 
110.934004209936, 287.134004209936, 122.634004209936, 197.834004209936, 
379.334004209936), bar = structure(c(3L, 8L, 1L, 5L, 10L, 8L, 
7L, 9L, 8L, 10L, 9L, 8L, 8L, 9L, 2L, 3L, 5L, 6L, 9L, 1L, 3L, 
5L, 6L, 8L, 7L, 9L, 2L, 3L, 2L, 2L, 3L, 1L, 5L, 10L, 4L, 7L, 
5L, 6L, 8L, 8L, 1L, 8L, 8L, 9L, 5L, 6L, 5L, 6L, 7L, 9L, 1L, 9L
), .Label = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"
), class = "factor")), .Names = c("foo", "bar"), row.names = c(NA, 
-52L), class = "data.frame")

在此处输入图片说明

I think it may have to do with stat :

Stats

The default stat used with geom_joy is stat_joy. However, it may not do exactly what you want it to do, and there are other stats that can be used that may be better for your respective application.

First, stat_joy estimates the data range and bandwidth for the density estimation from the entire data at once, rather than from each individual group of data. This choice makes joyplots look more uniform, but the density estimates can in some cases look quite different from what you would get from geom_density or stat_density. This problem can be remidied by using stat_density with geom_joy. This works just fine, we just need to make sure that we map the calculated density onto the height aesthetic.

Function geom_joy() estimates density function which is not bounded by min/max value of your data. Because you've supplied only a few data points, ranges of densities are too wide. You can see it here:

ggplot(results, aes(foo, bar)) + 
 geom_point() +
 geom_joy(alpha=.3)   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM