Reputation: 2429
Both my x and y-axis have variation in it, and thus have a corresponding confidence interval (xaxis.CI low and xaxis.CI.up). I want to plot x vs yaxis with the vertical and horizontal CIs, colored by dose in ggplot2. I also want to connect all the points by a line
xaxis <- c(5,10,9,30,2,4)
yaxis <- c(15,10,90,3,12,6)
xaxis.cI.low <- xaxis + 3
xaxis.cI.up <- xaxis - 3
yaxis.cI.low <- yaxis - 3
yaxis.cI.up <- yaxis + 3
dose <- c(100,200,300,400,500,600)
df <- data.frame(xaxis, yaxis, xaxis.cI.low, xaxis.cI.up, yaxis.cI.low, yaxis.cI.up, dose)
Upvotes: 1
Views: 784
Reputation: 4456
I think the answers in ggplot2 : Adding two errorbars to each point in scatterplot is what you need:
ggplot(data = df,aes(x=xaxis, y=yaxis, color=dose)) +
geom_point() +
geom_errorbar(aes(ymin=yaxis.cI.low, ymax=yaxis.cI.up)) +
geom_errorbarh(aes(xmin=xaxis.cI.low, xmax=xaxis.cI.up))
Upvotes: 1