r中的堆积条形图与汇总数据 [英] Stacked bar plot in r with summarized data
问题描述
这些数据代表了一个模拟比较自举置信区间和基于标准参数置信区间的模拟在t分布上。数据已被汇总。这是我的data.frame的样子:
test cr type2
1 Bootstrap 0.406 0.596
2 T检验0.382 0.618
cr =正确拒绝,type2 =类型2错误
我想要做的是制作一个堆叠的条形图,每个测试都有一个条形图。酒吧应该与cr和type2堆积,所以他们的高度应该总结为1。
任何帮助/建议将非常感激!
Espen
library(ggplot2)
d < - read.table(textConnection(test cr type2
Bootstrap 0.406 0.596
$ b ggplot(melt(d,id =test),aes(b $ b T-test 0.382 0.618),head = TRUE)
library(reshape2) test,value,fill = variable))+
geom_bar(stat =identity,position =stack)
I'm New to r. Im trying to make a stacked bar plot. I could make it work using the barplot function. 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.
The data represents a simulation comparing a bootstrap confidence interval against a standard parametric confidence interval based on the t-distribution. The data is already summarized. This is how my data.frame look like:
test cr type2
1 Bootstrap 0.406 0.596
2 T-test 0.382 0.618
cr = correct rejection, type2 = type 2 errors
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.
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")
这篇关于r中的堆积条形图与汇总数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!