簡體   English   中英

在基於百分位數的箱線圖上向晶須添加水平條

[英]Add horizontal bars to whiskers on percentile based boxplot

我的數據和圖為:

new_df <- structure(list(Group = c("k__Fungi; p__Ascomycota; c__Eurotiomycetes; o__Chaetothyriales; f__Chaetothyriaceae; g__unidentified", 
"k__Fungi; p__Ascomycota; c__Eurotiomycetes; o__Chaetothyriales; f__Chaetothyriaceae; g__unidentified", 
"k__Fungi; p__Ascomycota; c__Eurotiomycetes; o__Chaetothyriales; f__Chaetothyriaceae; g__unidentified", 
"k__Fungi; p__Ascomycota; c__Eurotiomycetes; o__Chaetothyriales; f__Chaetothyriaceae; g__unidentified"
), Percentile_0 = c(1, 1, 1, 1), Percentile_25 = c(1, 17.75, 
8, 99.5), Percentile_50 = c(1, 48, 32, 215.5), Percentile_75 = c(3, 
93, 51.25, 343.75), Percentile_100 = c(28, 337, 104, 788), Type = c("T1", 
"T2", "T3", "T4")), row.names = c(NA, -4L), class = "data.frame")


#plot 
ggplot(data = new_df, aes(x =Group, group = Type, fill = Type)) +
    geom_boxplot(
      stat = "identity",
      aes(
        ymin = Percentile_0,
        lower = Percentile_25,
        middle = Percentile_50,
        upper = Percentile_75,
        ymax = Percentile_100
      )
    ) +
    theme_classic()

在此處輸入圖片說明

我想在這個線程說明添加水平晶須這里

由於您已經計算了晶須末端的值,因此可以直接使用geom_errorbar() ,而不必像給出的鏈接中那樣通過stat_boxplot()來使用。

您將需要顯式躲避誤差線以匹配默認的箱形圖躲避。

geom_errobar()所需的美觀geom_errobar()yminymax 我將它們放在geom_errorbar()層中。 由於將它們同時用於箱線圖和錯誤欄,因此可以將它們移至全局aes()以避免重復。

ggplot(data = new_df, aes(x = Group, group = Type, fill = Type)) +
    geom_errorbar(aes(ymin = Percentile_0, 
                      ymax = Percentile_100), 
                  width = 0.5, 
                  position = position_dodge(width = 0.9) ) +
    geom_boxplot(
        stat = "identity",
        aes(
            ymin = Percentile_0,
            lower = Percentile_25,
            middle = Percentile_50,
            upper = Percentile_75,
            ymax = Percentile_100
        )
    ) +
    theme_classic()

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM