I have performed some tests and want to create some plots (here with "Asymmetry" values.
I try to create a plot with "Asymmetry" values depending on the "Classification" (Classification = EcoFlex, Classic, Select) of the samples with ggplot.
I use "pivot_longer" to pivot the data frame as i have the asymmetry values in separate columns in my table (Asymmetry [-] 2, Asymmetry [-] 3 and Asymmetry [-] 4). I try to do the same with the standard deviation values (SDAs2,SDAs3,SDAs4)
Here is my code:
Rohdaten_Balkendiagramm1 <- filter(Rohdaten_Balkendiagramm_ohne_Zeochem, `Test Hypothesis` == "Benchmark/performance tests of NP cartridges")
longer_data <- Rohdaten_Balkendiagramm1 %>%
pivot_longer(c(`Asymmetry [-] 2`,`Asymmetry [-] 3`,`Asymmetry [-] 4`), names_to = "SampleContent", values_to = "Asymmetry")
longer_data <-longer_data %>%
pivot_longer(c(`SDAs2`,`SDAs3`,`SDAs4`), names_to = "SD", values_to = "SDAs")
ComparisonSupplier <- ggplot(longer_data, aes(x=`Classification`, y=Asymmetry,
fill=`Measurement Description and Identification`), na.rm = FALSE) +
geom_bar(stat="identity", position=position_dodge(width =1), width = 0.65) +
scale_fill_manual(values = c("goldenrod3", "brown3", "cadetblue1",
"cadetblue2", "goldenrod4", "cadetblue3", "cadetblue4")) +
facet_wrap(vars(SampleContent), nrow = 1) +
theme(legend.position="bottom",legend.justification="left", plot.title =
element_text(hjust = 0.5), legend.text = element_text(size = 6)) +
#geom_hline(yintercept=300, linetype="solid", color = "red") +
#geom_hline(yintercept=245, linetype="dashed", color = "red") +
labs(title = "XXX",
subtitle = "XXX",
caption = "XXX",
fill= "") +
guides(fill =(guide_legend(nrow = 3)))
plot(ComparisonSupplier + geom_hline(yintercept = 1.0, color = "red", linetype = "dotted")+
geom_errorbar(stat = "identity", data=longer_data , aes(ymin=Asymmetry-
`SDAs`, ymax=Asymmetry+`SDAs`), position=position_dodge(1.0), width=.4))
With this code, i can show 3 different Asymmetry values in one figure:
Why are the columns so different in width? I can't change that somehow.
But my biggest problem is that the error bars are displayed for each column, with multiple error bars. I think the following code is not correct:
longer_data <-longer_data %>%.
pivot_longer(c(SDAs2,SDAs3,SDAs4), names_to = "SD", values_to = "SDAs")
How can I correct this? The error bars are each duplicated for Asymmetry [-] 2 on Asymmetry [-] 3 or Asymmetry [-] 4 for the respective column. As you can see in the figure
R assigns to each "asymmetry value" the standard deviation of each asymmetry value and therefore add all 3 standard deviations to each column plot (see bar plot above).
Unfortunately, I am not allowed to share pictures. Stackoverflow adds a link instead. Can you open that link?
EditII = It worked, @Stefan. Thanks! enter image description here

