我正在尝试根据其变量(男性或女性)更改条形的填充颜色
这是我的有效代码:
ggplot(sex_excercise_genhlth, aes(genhlth, prop_exer, fill=sex)) +
geom_bar(stat="identity", colour="black", position="dodge" ) + labs(title="Proportions of males to females who exercised in last 30 days compared to their general health", x="General Health", y="Proportion Exercise")
当我添加以下代码时,我得到一个错误:
+scale_fill_manual(values=c(“blue”,“pink”))
答案 0 :(得分:0)
以下是一个有效的示例,说明了如何在用例中正确使用scale_fill_manual
:
首先,我将创建一些虚拟数据:
df <- data.frame(sex = rep(c("Male", "Female"), 5),
place = rep(letters[1:5], each = 2),
vals = rep(c(0.1, 0.2), 5) + seq(0.9, 0.45, -0.05))
现在是情节
ggplot(data = df, aes(x = place, y = vals)) +
geom_bar(stat = "identity",
colour = "black",
aes(fill = sex),
position = "dodge") +
labs(title="Proportions of people exercising",
x="General Health",
y="Proportion Exercise") +
scale_fill_manual(values = c("pink", "blue"))