r - add segments to barchart (discrete x-axis) in ggplot2 -
i trying draw segments on each bar of barchart ggplot2
. know how continuous x-axis, not discrete axis. did kind of "hack" making-up line text.
it looks nice in picture, don't legend "limit" metal concentration and, of all, length of segment changes every time zoom in or out.
does know geometry implement better?
df = data.frame('metal'=c("cu", "fr", "zn"), 'observed'=c(550, 60, 100), 'limit'=c(200, 150, 120)) ggplot(data=df) + aes(x=metal) + geom_bar(aes(y=observed), stat="identity", fill="grey") + geom_text(aes(y=limit, label="_____________"), size=rel(6), color="red")
edit:
the question close this one
adapted this answer
ggplot(data=df) + aes(x=metal) + geom_bar(aes(y=observed), stat="identity", fill="grey") + geom_errorbar(aes(y=limit,ymin=limit,ymax=limit,colour="limit"))
Comments
Post a Comment