我是在 R 中制作欢乐图的新手。下面是我用一些模拟数据制作的图。不过我很困惑,因为我的数据变量 foo 不包含负值,但结果图表明:
library(ggjoy)
p <- ggplot(results, aes(foo, bar)) + geom_joy()
数据是:
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")
我认为这可能与stat:
统计数据
与 geom_joy 一起使用的默认统计数据是 stat_joy。但是,它可能不会完全按照您想要的方式执行,并且可以使用其他统计信息,这些统计信息可能对您各自的应用程序更好。
首先,stat_joy 一次从整个数据而不是从每个单独的数据组估计密度估计的数据范围和带宽。这种选择使joyplots 看起来更加统一,但在某些情况下,密度估计可能看起来与您从geom_density 或stat_density 得到的完全不同。这个问题可以通过使用 stat_density 和 geom_joy 来解决。这很好用,我们只需要确保将计算出的密度映射到高度美学上。