Why won't the geom_hline color be the color I selected?

26 Views Asked by At

I wrote the following code (changed the the data to mtcars). The problem is I want the line I put in which makes sense for the data I'm using to be green for the bottom line and red for the top line. No matter what I change the color to it doesn't change the line. I've used both "color" and "colour". What am I doing wrong?


test_test <- ggplot(mtcars, aes(x= mpg, y = wt , label =  wt)) + 
geom_col(fill = "blue") + 
geom_text(size = 2.5, nudge_x = 1, nudge_y = .2, 
          check_overlap = TRUE)+
theme(axis.text.x = element_blank(), 
      plot.title = element_text(hjust = .5), 
      legend.position = "none") +
geom_hline(aes(yintercept = 3.53, colour = "Green"))+ 
geom_hline(aes(yintercept = 5, color = "Green")) + 
ggtitle ("Test test")
1

There are 1 best solutions below

0
On

Your need to specify the color out of the aes() parameter. Like this:

test_test <- ggplot(mtcars, aes(x= mpg, y = wt , label =  wt)) + 
geom_col(fill = "blue") + 
geom_text(size = 2.5, nudge_x = 1, nudge_y = .2, 
          check_overlap = TRUE)+
theme(axis.text.x = element_blank(), 
      plot.title = element_text(hjust = .5), 
      legend.position = "none") +
geom_hline(aes(yintercept = 3.53), colour = "green")+ 
geom_hline(aes(yintercept = 5), color = "red") + 
ggtitle ("Test test")

enter image description here