Reputation: 25
I would like to add an error bar of 1.555 % to each data point. Or have a back ground band of +/- 1.555 behind the points. I've done the calculation elsewhere based on a different set which is not featured in the plot. I can't seem to add this vertical error bar.
library(ggplot2)
carb<-read.table("total_carb", header= TRUE)
p<- ggplot(carb,aes(x=Sample, y=TC, color="Total Carbonate")) + geom_line() + geom_point()
p + scale_x_continuous(name="Core Depth (cm)") + scale_y_continuous(name="Carbonate (%)")
+ geom_errorbar(aes(ymin=TC-1.555, ymax=TC+1.555), width=.2)
Error in +geom_errorbar(aes(ymin = TC - 1.555, ymax = TC + 1.555), width = 0.2) : invalid argument to unary operator
Upvotes: 0
Views: 1210
Reputation: 408
Try adding a columns to your dataset that contain the values for the error. For example:
carb$error <- carb$data*0.015
carb$lower <- carb$data - carb$error
carb$upper <- carb$data + carb$error
p<- ggplot(carb,aes(x=Sample, y=TC, color="Total Carbonate")) + geom_line() + geom_point()
p + scale_x_continuous(name="Core Depth (cm)") + scale_y_continuous(name="Carbonate (%)")
+ geom_errorbar(aes(ymin=lower, ymax=upper), width=.2)
Upvotes: 0
Reputation: 2045
I think it should read
+ geom_errorbar(mapping=aes(ymin=TC-1.555, ymax=TC+1.555), width=.2)
Upvotes: 1