My data set is as follows
dput(data2)
structure(list(School = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L,
3L, 3L), .Label = c("School1", "School2", "School3"), class = "factor"),
Year = c(2015L, 2014L, 2013L, 2015L, 2014L, 2013L, 2015L,
2014L, 2013L), Rate = c(70L, 50L, 30L, 80L, 90L, 11L, 60L,
50L, 40L)), .Names = c("School", "Year", "Rate"), class = "data.frame", row.names = c(NA,
-9L))
School Year Rate
1 School1 2015 70
2 School1 2014 50
3 School1 2013 30
4 School2 2015 80
5 School2 2014 90
6 School2 2013 11
7 School3 2015 60
8 School3 2014 50
9 School3 2013 40
I plot this data using ggplot2 as follows
library(ggplot2)
ggplot(data=data2,aes(x=School,y=Rate)) +
geom_bar(stat = "identity", fill="orange",width = 0.5) +
geom_hline(aes(yintercept = 220,color="red"), size = 1) +
coord_flip()
which gives me the following chart and I am trying to rotate the line in the legend as follows
I have read posts on Stack Overflow which mentioned that the lines in the legends are shown vertically but that only happens when you use geom_linerange but I cannot use that for my example.
Please can someone help me understand how I can rotate the line within the legend.
One alternative that has come to mind to navigate the viewports using the grid package and then see whether I am able to rotate the viewport used by the legend key.