Hi Carol,
>Has there been any new solution, thoughts on this thread since it was
>posted?
>
>So if I take the following example, the dashed red line should go to the
>top of histogram which is unknown (instead of yend = 9) but x, y, xend
>are known if it is possible to do it with ggplot2
I think you would need to generate the value for yend outside of ggplot.
The following code pretty much (apart from not going up to 1 on the
x-axis, and I¹m not sure why the example does) reproduces your example
without the 9 being supplied:
# data to be histogrammed
my.vec <-c(0.41, 0.42, 0.47, 0.47, 0.49, 0.50, 0.51, 0.55, 0.56, 0.57,
0.59, 0.61, 0.62, 0.65, 0.68, 0.69, 0.70, 0.75, 0.78, 0.79)
# x-point of interest
xpoint <- 0.75
# Define binning
bin.origin <- 0.2
bin.width <- 0.2
# Create table
my.breaks <- seq(bin.origin,1,bin.width) # the 1 could be replaced by
something related to max(my.vec), bin.width and bin.origin
my.his <- table(cut(my.vec,my.breaks))
ypoint <- as.numeric(my.his[which(my.breaks>xpoint)[1]-1])
ggplot() +
geom_bar(data=data.frame(x=my.vec),origin=bin.origin,
binwidth=bin.width,
aes(x=x,fill =..count..), colour='black') +
geom_segment(aes(x=xpoint, y=0, xend=xpoint, yend=ypoint),
linetype="dashed", color="red")
Hope this helps.
Ron.