Create error bars for scatter plot of multiple datasets


Hi all- I am trying to generate error bars for a scatter plot, where each set of points has a different length and associated error. I have looked around quite a bit but havent been able to find anything that quite applies to what I am doing here.

I installed plotrix, as I read that this has the capability of adding error bars. However, I cannot get the error bars to actually show up, and when I put plotCI as a leading command rather than points (for subsequent data sets), my points disappear. I will attach the code for what I am doing below.

#this is how i generate error for the first set of points. I also have to generate separate error bars for each of the other 3 sets of data points (not shown). In all cases, the upper error is equal to the lower error.
uiw = 100*(AGUpostercalcs_chew_Sheet1_1_Precip_SD/AGUpostercalcs_chew_Sheet1_1_Precip US Budyko (mm/yr))

title(main = “Late pleistocene lake highstands”)
plot(AGUpostercalcs_chew_Sheet1_1_`Age (ka)`, AGUpostercalcs_chew_Sheet1_1_% Modern, xlab = “Time before present (ka)”, ylab = “Relative Precipitation (%)”, ylim=c(40,260), xlim=c(13,22.5), type = “p”, pch = 18, cex = 1.9, cex.axis = 1.2, cex.lab = 1.3, col = “black”)

new =TRUE
points(AGUpostercalcs_chew_Sheet1_1_`Age (ka)`, AGUpostercalcs_chew_Sheet1_1_% Modern_1, type = “p”, pch = 19, col = “black”, cex = 1.7, cex.axis = 12)
points(AGUpostercalcs_surprise_Sheet1_1_`Age (ka)`, AGUpostercalcs_surprise_Sheet1_1_% Modern, type = “p”, pch = 18, col = “dodgerblue”, cex = 1.9, cex.axis = 12)
points(AGUpostercalcs_surprise_Sheet1_1_`Age (ka)`, AGUpostercalcs_surprise_Sheet1_1_% Modern_1, type = “p”, pch = 19, col = “dodgerblue”, cex = 1.7, cex.axis = 12)
#yplus_surp = 100*(AGUpostercalcs_surprise_Sheet1_1_Precip_SD/AGUpostercalcs_surprise_Sheet1_1_Precip US Budyko (mm/yr))
#yplus_chew = 100*(AGUpostercalcs_chew_Sheet1_1_Precip_SD/AGUpostercalcs_chew_Sheet1_1_Precip US Budyko (mm/yr))
#yplus_surp_new = 100*(AGUpostercalcs_surprise_Sheet1_1_Precip_SD_1/AGUpostercalcs_surprise_Sheet1_1_Precip US Budyko (mm/yr))
#yplus_chew_new = 100*(AGUpostercalcs_chew_Sheet1_1_Precip_SD_1/AGUpostercalcs_chew_Sheet1_1_Precip US SW Budyko (mm/yr)),yminus, add = True, lty=1)
legend(“bottomleft”, legend=c(“Lake Chewaucan”,“Lake Chewaucan (new Budyko parameter)”, “Lake Surprise”, “Lake Surprise (new Budyko parameter)”),
col=c(“black”,“black”, “dodgerblue”,“dodgerblue”), pch = c (18, 19, 18, 19), lty=c(1,1), cex=0.8, bty=“n”)

Anyway, I hope this is enough information to go on. Sorry for what may be a fairly basic question and thanks for the help!


I’m not sure about plotrix, but ggplot has some pretty easy methods to apply error bars.

Also, for ease of understanding can you put three backticks “```” before and after your code? It should then format nicely and be easy to understand.