In ggplot, assign a variable/category to a specific color?
1
1
Entering edit mode
7.7 years ago
james.lloyd ▴ 100

I have a dataframe in R and I want to plot a subset of the plot as a line graph in ggplot. I have 8 different variables, with no guarantee all 8 will appear in the subset I want to plot. How can I for ggplot to assign variable A to a particular color code #B35806 and H to #542788? I tried to assign this to the dataframe itself (a column where if A is present, #B35806 would be) and calling on that in ggplot but that did not help

geom_line(aes(color=Line_color))

Advice would be very useful to this R noob.

R ggplot plots colors • 48k views
ADD COMMENT
3
Entering edit mode
7.7 years ago
james.lloyd ▴ 100

I found a solution

p + scale_colour_manual(values = c("A" = "#E08214", "B" = "#E08214"))
ADD COMMENT

Login before adding your answer.

Traffic: 2523 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6