0

R 相当新,所以请原谅粗略的代码!我有一群标记的昆虫,我每个月都会跟踪它们。标记水平 (ppm) 随时间衰减。我想使用 ggridges 显示每月密度图,其中显示背景(未标记)人口的第一个月(9)与接下来的每个月一起出现,以显示标记和未标记人口之间的信号差异。不知道如何让背景密度图与每个月的图一起显示。这是我尝试过的:


        df2 <- df1 %>% filter(!is.na(ppm)) %>% 
           mutate(Month = factor(Month, levels=c(9,10,11,12,1,2,3,4,5,6,7,8))) %>%
           filter(Month %in% c(7,6,5,3,11,10,9)) %>% 
           mutate(month2 = "9")

        df1 %>% filter(!is.na(ppm)) %>% 
           mutate(Month = factor(Month, levels=c(9,10,11,12,1,2,3,4,5,6,7,8))) %>%
           filter(Month %in% c(7,6,5,3,11,10,9)) %>% 
           ggplot(., aes(x = ppm, y = Month, height = ..density.., fill=Month)) +
           geom_density_ridges(scale = 2.8, stat = "density", alpha=0.8) +
           scale_y_discrete(expand = c(0.01, 0)) +
           scale_x_log10(limits=c(125, 190), breaks=seq(125, 190, 10)) +
           scale_fill_manual(values=c("royalblue", "red3", "darkred", "firebrick3", "tomato2", 
               "indianred1", "mediumpurple3")) +
           theme_ridges() + theme(legend.position = "none") +
           geom_density_ridges(data=df2, aes(x = ppm, y = month2, height = ..density..), scale = 2.8, 
                stat = "density", alpha=0.5, fill='grey')
4

0 回答 0