【发布时间】:2014-05-14 20:12:47
【问题描述】:
我有 this 数据集并使用此 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)
得到以下结果:
现在我需要将 95 个百分位和 5 个百分位添加到绘图中。这些数字在this 数据集(NFPnumbers(95%)和 FPnumbers(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))
但结果看起来不够好。
geom_boxplot() 也不行:
geom_boxplot(aes(x = id, y = long$FPnumbers)) +
geom_boxplot(aes(x = id, y = long$NFPnumbers))
【问题讨论】:
-
附带问题:颜色为情节带来了哪些额外信息?
-
当我从
ggplot中删除facet_grid(type ~ .)时,颜色有助于将条与“图例”链接起来。 -
另一种选择是更改因子水平,图例将变得过时。只是大声思考......
标签: r ggplot2 percentile