1

I am trying to map color variable to geom_hline, but doesn't seem to work like other geometries. Neither of these work, in each case, rendering a fixed black line.

ggplot(data.frame(x=0,y=0,series="ABC"),aes(x,y,color=series))) + 
  geom_point() +
  geom_hline(yintercept=0,show.legend = TRUE)

ggplot(data.frame(x=0,y=0),aes(x,y)) + 
  geom_point() +
  geom_hline(yintercept=0,aes(color="ABC"),show.legend = TRUE)

Is this a bug, or is there some syntax I am missing?

Nicholas Hamilton
  • 10,044
  • 6
  • 57
  • 88

1 Answers1

5

If you need to set aesthetics for the geom_hline() then also yintercept= should be put in aes() call.

ggplot(data.frame(x=0,y=0,series="ABC"),aes(x,y,color=series)) + 
      geom_point() +
      geom_hline(aes(yintercept=0,color=series))

ggplot(data.frame(x=0,y=0),aes(x,y)) + 
      geom_point() +
      geom_hline(aes(yintercept=0,colour="ABC"))
Didzis Elferts
  • 95,661
  • 14
  • 264
  • 201