如何使用已计算的值在 ggplot2 图上绘制 95 百分位数和 5 百分位数?

Rle*_*ner 6 r percentile ggplot2

我有这个数据集并使用这个 R 代码:

library(reshape2)
library(ggplot2)
library(RGraphics)
library(gridExtra)

long <- read.csv("long.csv")
ix <- 1:14

ggp2 <- ggplot(long, aes(x = id, y = value, fill = type)) +
    geom_bar(stat = "identity", position = "dodge") +
    geom_text(aes(label = numbers), vjust=-0.5, position = position_dodge(0.9), size = 3, angle = 0) +
    scale_x_continuous("Nodes", breaks = ix) +
    scale_y_continuous("Throughput (Mbps)", limits = c(0,1060)) +
    scale_fill_discrete(name="Legend",
                        labels=c("Inside Firewall (Dest)",
                                 "Inside Firewall (Source)",
                                 "Outside Firewall (Dest)",
                                 "Outside Firewall (Source)")) +
    theme_bw() +
    theme(legend.position="right") +
    theme(legend.title = element_text(colour="black", size=14, face="bold")) +
    theme(legend.text = element_text(colour="black", size=12, face="bold")) +
    facet_grid(type ~ .) +
plot(ggp2)
Run Code Online (Sandbox Code Playgroud)

得到以下结果: 在此输入图像描述

现在我需要将 95 个百分位数和 5 个百分位数添加到图中。这些数字是在数据集中计算的(NFP 数字(95 个百分点)和 FP 数字(5 个百分点)列)。

它似乎boxplot()可以在这里工作,但我不确定如何将它与 ggplot 一起使用。 stat_quantile(quantiles = c(0.05,0.95))也可以工作,但是该函数自己计算数字。我可以在这里使用我的号码吗?

我也尝试过:

geom_line(aes(x = id, y = long$FPnumbers)) +
geom_line(aes(x = id, y = long$NFPnumbers))
Run Code Online (Sandbox Code Playgroud)

但结果看起来不够好。

geom_boxplot()效果不太好:

geom_boxplot(aes(x = id, y = long$FPnumbers)) +
geom_boxplot(aes(x = id, y = long$NFPnumbers))
Run Code Online (Sandbox Code Playgroud)

ton*_*nov 2

有几种合适的几何图形,geom_errorbar其中之一是:

ggp2 + geom_errorbar(aes(ymax = NFPnumbers, ymin = FPnumbers), alpha = 0.5, width = 0.5)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

不知道有没有办法去掉中线。