0

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

1 Answers1

1

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") 
baptiste
  • 75,767
  • 19
  • 198
  • 294