【发布时间】:2021-09-14 19:27:59
【问题描述】:
我正在使用 ggplot2 创建条形图,并希望使用 RColorBrewer 调色板来填充图表的各个条形。出于某种原因,调色板仅将一种颜色应用于图形的所有条形。这是我到目前为止的代码:
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")
【问题讨论】:
-
如果您创建一个小的可重现示例以及预期的输出,这将更容易提供帮助。阅读how to give a reproducible example。
标签: r ggplot2 colors geom-bar palette