I currently have a bar graph in R (ggplot2) with dollar amounts of an account on the y-axis and Year from 1990's to current on the x-axis. I'd like to add a line at the $50M point in the bar for 2017 - to indicate a cap. I was wondering if I can do this in R, or I will have to customize the image after export. I'd also like to add one or two "projected amount" bars for 2018 and 2019, with these being transparent with dotted outlines to indicate they are projections. Is this possible?
Asked
Active
Viewed 114 times
-1
-
Please share sample of your data using `dput()` (not `str` or `head` or picture/screenshot) so others can help. See more here https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example?rq=1 – Tung Sep 30 '18 at 21:00
-
3Execute this at your console: `install.packages("fortunes"); fortunes::fortune("Yoda")` – IRTFM Sep 30 '18 at 21:12
1 Answers
0
It certainly is, if you post your data and code!
If you're using ggplot: add this line, replacing the y and yend values with 50 (adjust for whatever units the y axis is in). If you only want the bars to appear over certain x values, play around with the x and xend arguments.
annotate(geom = 'segment', y = Inf, yend = Inf, x = -Inf, xend = Inf,color = 'black', size = 2)
And for the transparent lines, use the alpha argument; for dashed lines, use linetype:
annotate(geom = 'segment', y = Inf, yend = Inf, x = -Inf, xend = Inf,color = 'black', size = 2, alpha = .1, linetype="dashed")

Grubbmeister
- 857
- 8
- 25