I have a dataset like below. I am trying to draw horizontal lines for different Band with its colors (Green, Yellow,....,Black), y-axis as Price. I am trying to use facet_grid(.~ Band)
.
My code below are giving me all the same lines for every Band. Seems like the facet didn't work here.
g <- ggplot(df, aes(y=Price)) +
facet_grid(.~ Band) +
geom_hline(yintercept=df$Price[1], colour="green") +
geom_hline(yintercept=df$Price[2], colour="yellow") +
geom_hline(yintercept=df$Price[3], colour="pink") +
geom_hline(yintercept=df$Price[4], colour="red") +
geom_hline(yintercept=df$Price[5], colour="black")
print(g)
Thanks! Brenda
Line Price Band
Green 1584 A) 1--9
Yellow 1512 A) 1--9
Pink 1386 A) 1--9
Red 1152 A) 1--9
Black 1044 A) 1--9
Green 1566 B) 10--24
Yellow 1476 B) 10--24
Pink 1386 B) 10--24
Red 1152 B) 10--24
Black 1044 B) 10--24
Green 1512 C) 25--49
Yellow 1440 C) 25--49
Pink 1386 C) 25--49
Red 1152 C) 25--49
Black 1044 C) 25--49
Green 1494 D) 50--99
Yellow 1422 D) 50--99
Pink 1386 D) 50--99
Red 1080 D) 50--99
Black 972 D) 50--99