Hi everyone,
I am not an R studio pro and I'm struggling quite a bit to create a specific diagram and after looking at every forum not understanding the code I hope someone may help me.
So basically, as the title says, I want to create a stacked barplot with standard deviation error bars.
If my understanding is right, I have to calculate myself the position of the error bars, which is where I'm stuck.
I created already my stack barplot using the very easy following line:
"barplot(as.matrix(dataset))"
I know I can also use ggplot2 but I was also struggling to understand every entry and since my data is already normalised to 100%, the barplot works for me.
But now is my problem, I calculated the standard deviation on Excel all of my data but I don't know how add it into R.
Here is a picture of my own stacked barplot on the right and the other one is a picture of what I would want, on the left.
Below is an example using a subset of the mtcars data. The sample data has mean and standard deviation by cyl and carb. As you point out, the position of the error bars needs to be calculated. I did this by first arranging the data set (this may take some trial and error to get right), grouping by cyl, and then taking the cumulative sum of mean_hp. This new column is the center point of the error bar, from which the standard deviation is added to and subtracted from in geom_errorbar().