我试图改变以下情节中的一些颜色:
下面的代码给了我以下情节,已经相当漂亮了:
我仍然希望更改绘图中4个条的颜色,例如“green4”、“darkgreen”、“orangered3”和“red3”,但不更改绘图中的任何其他内容(例如图例中使用的标签(当然,图例中的颜色也应该更改))。我的数据(df)有三个变量。变量“V1n”只是因子变量V1的数字版本。这只是最后一点我不能左右我的头,有人知道如何改变默认使用的四种颜色吗?
library(ggplot2)
library(dplyr)
glimpse(df)
# Observations: 300
# Variables: 3
# $ METING.f <fctr> Meting 0, Meting 0, Meting 0, Meting 0, Meting 0,...
# $ V1n <int> 2, 1, 2, 2, 2, 2, 2, 1, 2, 1, 2, 1, 1, 2, 2, 2, 1,...
# $ V1 <fctr> Ja, meerdere, namelijk..., Ja, Ja, meerdere, name...
ggplot(df, aes(x = V1n, fill = V1)) +
geom_bar(aes(y = (..count..)/tapply(..count..,..PANEL..,sum)[..PANEL..])) +
scale_y_continuous(labels = scales::percent) +
geom_text(aes(y = ((..count..)/sum(..count..)),
label = scales::percent((..count..)/tapply(..count..,..PANEL..,sum)[..PANEL..])),
stat = "count", vjust = -0.25) +
facet_grid(.~ METING.f) +
scale_fill_discrete(name = "Beschikt uw instelling over een\naandachtsfunctionaris kindermishandeling?\n") +
labs(title = " ",
x = "Vraag 1",
y = "Percentage") +
theme(axis.text.x = element_blank(),
axis.ticks.x=element_blank())