I am using 'mpg' data set and ggplot2 package to create a bar plot, and it is required that the colors of bars are defined by the 'class' variable such that the color for the value '2seater' is red, for the value 'pickup' is green, and all others are white. Here is my code:
mpg %>% ggplot(aes(class), fill = x) + geom_bar(width = 0.7, color = "black", size = 0.8) +
scale_fill_manual(values = c("2seater" = "red",
"compact" = "white",
"midsize" = "white",
"minivan" = "white",
"pickup" = "green",
"subcompact" = "white",
"suv" = "white"))
The problem is, when I execute this code, the colors of bars remain as default. Could anyone tell me what goes wrong with my code? Thank you very much