Visualization of Groups of Poisson random samples using ggridges

可紊 提交于 2019-12-04 17:43:17

You need to create a grouping variable that contains both Month and location. You can do that by using paste0(Month, location). For now, I'm leaving out the text labels, though they may be possible with a little more thought as well. (But I think they'd make the figure too busy.)

ggplot(rp_data,
       aes(x = value, y = Month,
           group = paste0(Month, location),
           fill = paste0(Month, location))) +
  geom_density_ridges2(stat = "binline", binwidth = 1,
                       scale = 0.95, alpha = 0.7) +
  scale_x_continuous(breaks = c(0:12), limits = c(-.5, 13),
                     expand = c(0, 0), name = "random value") +
  scale_y_discrete(expand = c(0.01, 0), name = "Month",
                   labels = c("5.0", "4.0", "3.0", "2.0", "1.0")) +
  scale_fill_cyclical(values = c("#0000B0", "#B00000",
                                 "#7070D0", "#FC5E5E")) +
  labs(title = "Poisson random samples location 1 different Month",
       subtitle = "sample size n=10") +
  guides(y = "none") +
  theme_ridges(grid = FALSE, center = TRUE)

Edit: Now with text labels.

ggplot(rp_data, aes(x = value, y = Month, group = paste0(Month, location), fill = paste0(Month, location))) +
  geom_density_ridges2(stat = "binline", binwidth = 1, scale = 0.95, alpha = 0.7) +
  geom_text(stat = "bin",
            aes(y = ceiling(group/2) + 0.95*(..count../max(..count..)),
                label = ifelse(..count..>0, ..count.., ""), color = location),
            vjust = 1.4, size = 3, binwidth = 1, fontface = "bold") +
  scale_x_continuous(breaks = c(0:12), limits = c(-.5, 13), expand = c(0, 0),
                     name = "random value") +
  scale_y_discrete(expand = c(0.01, 0), name = "Month",
                   labels = c("5.0", "4.0", "3.0", "2.0", "1.0")) +
  scale_fill_cyclical(values = c("#0000B0", "#B00000", "#7070D0", "#FC5E5E")) +
  scale_color_cyclical(values = c("white", "black")) +
  labs(title = "Poisson random samples location 1 different Month",
       subtitle = "sample size n=10") +
  guides(y = "none") +
  theme_ridges(grid = FALSE, center = TRUE)

Again, not sure it's a good idea, but there you go.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!