I am looking for help with my code. I have a dataset where many people were asked to score 5 different scenerios with a range of -5 to +5.
I then grouped the 2 groups to S and A as I am looking to compare these 2 groups. The data set is below:
Score<-c(-2, 3, 4, -1, 3, 4, 5, -1, 3, 5, -3, 3, 5, 1, -4, 5, -2,
1, 3, 4, -4, 2, -1, 3, 4)
Group<-c( "S", "S", "A", "S", "A", "S", "A", "S", "S", "A", "S", "A", "S", "A",
"S", "S", "A", "S", "A", "S", "A", "S", "S", "A", "S"
)
Scenerio_ID <-c(1, 2, 3, 4, 5, 1, 2, 3, 4, 5,
1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5)
CombinedTable<-data.frame(Score,Group, Scenerio_ID )
I am trying to perform the following:
Create a new column or table with the mean score for each Scenerio_ID and the 95% Confidence Intervals (Upper and Lower) for both group "A" and group "S".
I am trying to draw a graph where I have Score on the Y axis and Scenario on the x axis and for each scenerio, Group A and Group S. I want the mean point and the Upper and Lower 95% Confidence Intervals. Very similar to the picture I have just attached.
My code attempt at calculating the Mean and Confidence Interval for each Scenerio with respect to Group is this:
library(dplyr)
library(Rmisc)
library(ggplot2)
MeansCombinedTable <-
CombinedTable %>%
group_by(Group, Scenerio_ID) %>%
dplyr::summarise(avg_Score = mean(Score),
uci_Score = CI(Score)[1],
lci_Score = CI(Score)[3]) %>%
mutate(Scenerio_ID = Scenerio_ID %>% as.factor())
My attempt at drawing the plot is this:
CombinedTable %>%
ggplot(aes(x = Group, y = avg_Score, fill = Scenerio_ID)) +
geom_bar(stat = "identity", position = "dodge") +
geom_errorbar(aes(ymin = lci_Score, ymax = uci_Score), position = "dodge")
Would be incredibly grateful for any help with this as I have been working on this for a while and it is giving me a huge problem. Many thanks in advance.