[英]Stacked bar plot in r with summarized data
I'm New to r. 我是r的新手。 Im trying to make a stacked bar plot.
我正在尝试绘制堆积的条形图。 I could make it work using the barplot function.
我可以使用barplot函数使其工作。 However I could not work out how to make the legend look nice.
但是我不知道如何使图例看起来不错。 Now i'm trying to use ggplot2 but I really cant make the chart look correctly.
现在,我正在尝试使用ggplot2,但我真的无法使图表正确显示。
The data represents a simulation comparing a bootstrap confidence interval against a standard parametric confidence interval based on the t-distribution. 数据表示将自举置信区间与基于t分布的标准参数置信区间进行比较的模拟。 The data is already summarized.
数据已经汇总。 This is how my data.frame look like:
这是我的data.frame的样子:
test cr type2
1 Bootstrap 0.406 0.596
2 T-test 0.382 0.618
cr = correct rejection, type2 = type 2 errors cr =正确拒绝,类型2 =类型2错误
What I want to do is to make a stacked bar chart With one bar for each test. 我要做的是制作一个堆叠的条形图,每个测试有一个条形图。 The bars should be stacked With cr and type2 so their height should both summarize to 1.
条形图应与cr和type2堆叠在一起,因此它们的高度都应汇总为1。
Any help/suggestions would be very appreciated! 任何帮助/建议将不胜感激!
Espen 埃斯彭
You probably should reshape the data to long format, 您可能应该将数据重整为长格式,
library(ggplot2)
d <- read.table(textConnection("test cr type2
Bootstrap 0.406 0.596
T-test 0.382 0.618"),head=TRUE)
library(reshape2)
ggplot(melt(d, id="test"), aes(test, value, fill=variable)) +
geom_bar(stat="identity", position="stack")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.