0

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")
DaveArmstrong
  • 18,377
  • 2
  • 13
  • 25
trog12
  • 1
  • 1

1 Answers1

0

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

Lucca Nielsen
  • 1,497
  • 3
  • 16