rossig
rossig

Reputation: 19

Why is the color palette only applying one color to all bars?

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")

Upvotes: 0

Views: 168

Answers (1)

M.Viking
M.Viking

Reputation: 5398

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")

Upvotes: 1

Related Questions