It seems that what is required is segments rather than lines; that is, use geom_segment()
in place of geom_line()
. geom_segment
requires x and y coordinates for the start and end points of the segments. Getting the end y value is a bit unwieldy. But it works with your data frame assuming that there are 30 observations for each "Well", and that the order for "Sequence" is the same for each "Well".
library(ggplot2)
df = CombinedThickness2[CombinedThickness2$DepSequence == "Original",]
# Get the y end values
index = 1:dim(df)[1]
NWell = length(unique(df$Well))
df$DepthEnd[index] = df$Depth[index + dim(df)[1]/NWell]
BarWidth = 0.3
plot11 = ggplot(df,
aes(x = Well, y = Thickness, fill = Sequence, alpha = Visible)) +
geom_bar(stat = "identity", width = BarWidth) +
scale_y_reverse() + scale_alpha(guide = "none")
plot11 = plot11 +
geom_segment(aes(x = as.numeric(Well) + 0.5*BarWidth, xend = as.numeric(Well) + (1-0.5*BarWidth),
y = Depth, yend = DepthEnd, color = Sequence))
plot11
