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? enter image description here

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")) 

enter image description here


Comments

Popular posts from this blog

angularjs - Redirect to a new template in angular js -

Oracle SQL. How to select specific IDs where value of columns specify criteria? -

Desktop Launcher for Python Script Starts Program in Wrong Path (Linux) -