This is a test version of Biostars. For the public version, visit https://www.biostars.org.
In ggplot, assign a variable/category to a specific color?

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

1 answer

I found a solution

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

Log in to answer this question.