I want to use facet_wrap in R to split my plots based on a certain column. Here is a working example I reproduced from here:
set.seed(1)
df <- data.frame(age = runif(500, min = 10, max = 100),
group = rep(c("a", "b", "c", "d", "e"), 100))
#Plotting
ggplot(df, aes(age)) +
geom_histogram(aes(y = (..count..)), binwidth = 5) +
facet_wrap(~group, ncol = 3)
This produces plots, all in grey color (shown below). However, I want each plot be in a specific color. That is, they have the following color in order c("green","orange","blue","black", "red"). All bars in plot (a) be green, all in (b) be orange, and so on. These colors match my other plots and preserve consistency. How can I achieve this task? Thanks.
fill=group
to youraes()
call anduse a scale_fill_manual()
. – Limey