How to make all the bars blue except from the year 2005 that is red. My code doesn't do it. Is there a way to do this without specifying the color for every year in the data frame?
df <- data.frame(
Body_part = sample(c("Head", "Arm", "Leg", "Torso"), 1000, replace = TRUE),
Year = as.factor(sample(2003:2021, 1000, replace = TRUE))
)
ggplot(df, aes(x = fct_rev(fct_infreq(Body_part)), fill = Year)) +
geom_bar(position = "dodge", stat = "count") +
scale_fill_manual(values = c("blue", "2005" = "red")) +
theme_light() +
labs(title = "",
x = "",
y = "Count") +
coord_flip()

From
?scale_fill_manual:Noteworth is the
na.valuereference.Note that neither your plot nor this will show years other than
"2005"in the legend. An alternative that at least gives a hint about the others: