我是在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一次从整个数据估算密度估计的数据范围和带宽,而不是从每个单独的数据组估算。这种选择使得加热点看起来更加均匀,但在某些情况下,密度估计值可能与从geom_density或stat_density得到的值非常不同。使用stat_density和geom_joy可以解决此问题。这很好用,我们只需要确保将计算出的密度映射到高度美学上。
答案 0 :(得分:2)
函数geom_joy()
估计密度函数,该函数不受数据的最小值/最大值限制。因为您只提供了一些数据点,所以密度范围太宽。你可以在这里看到它:
ggplot(results, aes(foo, bar)) +
geom_point() +
geom_joy(alpha=.3)