Adding Errorbars to convoluted code

Hello everyone,

I received help on this forum recently to compile an xy scatter graph with points and lines. Now I'd like to add error bars to the points. However, I always get an error message, after I added the geom_errorbar code and then have RStudio show me the graphs. (Error in FUN(X[[i]], ...) : object 'name' not found)

I'll add 3 files to this post. One file is the code, the other two files are the used data tables for the lines and points in the graph. (I use excel for the sheets, so be aware of the import code) Any help is greatly appreciated.
Line.pdf (100.2 KB)
Point.pdf (73.2 KB)
R-Code.pdf (72.5 KB)

The files don't contain the code for the error bars, but are the working versions to produce the graphs.
The error bars are supposed to show the +- Standard Deviation (StDev) for the respective average points (Ave). The necessary values were precalculated in excel.


To help us help you, could you please turn this into a proper reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

I've tried to reduce the code to a small reprex, however, the error didn't pop up there.
This is the code of a single graph (the others are only reproductions with different values) with the error creating line:

lines <- read_excel("C:/R/Line.xlsx") 
points <- read_excel("C:/R/Points.xlsx") 
points <- points |> filter(name %in% c("A", "B", "C", "D", "E", "F", "G", "H"))|> 
mutate(name = factor(name, levels = c("A", "B", "C", "D", "E", "F", "G", "H"))) 
lines <- lines |> filter(name %in% c("+10_%", "fit", "-10_%")) |> 
mutate(name = factor(name, levels =c("+10_%", "fit", "-10_%"))) 
PropertyA <- ggplot(mapping = aes(x=Ave1, y=Ave3, group=name)) + 
geom_line(aes(linetype= name), data = lines) + 
scale_linetype_manual(values=c("dashed", "solid", "dashed"), labels = ~ gsub("_", " ", .x)) + 
geom_point(aes(color = name), data = points, size = 2) + 
geom_errorbar(aes (ymin=Ave3-StDev3, ymax=Ave3+StDev3), width = 0.2) +
labs(title="Property A", x = "Ave1", y = "Ave3", linetype = "Fit", color = "Tablets") + 
scale_color_manual(values = c("#5B9BD5", "#ED7D31", "#A5A5A5", "#FFC000", "#4472C4", "#70AD47", "#255E91", "#9E480E"), labels = ~ gsub("_", " ", .x)) + 
theme(legend.margin = margin(6, 6, 6, 6), legend.key = element_rect(fill = "white")) 

The faulty line is the fifth from the bottom.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.