0

I am using ggplot2 to create a bar graph and wanted to use an RColorBrewer palette to fill the individual bars of the graph. For some reason, the palette is only applying one color to all of the bars of the graph. This is the code I have so far:

prop_race_2018_plot <- ggplot(race_2018) +
geom_bar(mapping = aes(x = Race, y = X2018_Percentage, fill = "X2018_Percentage"),
       stat = "identity") +
labs(
title = "Patient Enrollment by Race, 2018",
x = "Race", # x-axis label
y = "Percentage of Patients Enrolled") +
scale_fill_brewer(palette = "Set2") +
scale_x_discrete(labels = c("American Indian/Alaska Native", "Asian", "Black",
                          "Native Hawaiian/Pacific Islander", "Other Race", 
                          "Unknown Race", "White")) +
theme(legend.position = "none")
rossig
  • 9
  • 1
  • It would be easier to help if you create a small reproducible example along with expected output. Read about [how to give a reproducible example](http://stackoverflow.com/questions/5963269). – Ronak Shah Jul 03 '21 at 03:22

1 Answers1

1

Remove the " quotes from around your fill= variable.

Also, you might actually want fill=Race.

gplot(race_2018) +
    geom_bar(mapping = aes(x = Race, y = X2018_Percentage, fill = Race), stat = "identity")
M.Viking
  • 5,067
  • 4
  • 17
  • 33