我在网上查找了许多示例代码片段,但是对于我一生来说,我无法弄清楚自己在做什么错。我在下面包含了提供该图表的r代码:
通常可以正常工作,除了:
-
我无法显示%s而不是计数(对于因子变量“ doctorate”),并且
-
“组”的颜色显示在图例中,而不显示在条形图中。
pg_doc <- ztemp.pg %>%
ggplot(aes(doctorate,group = group)) +
geom_bar(aes(y = ..prop..,fill = group),stat="count") +
geom_bar(position = position_dodge(preserve = "single")) +
scale_fill_manual(values=c("grey45","goldenrod2")) +
theme(legend.position = "bottom",legend.title=element_blank(),text = element_text(color="black"),#for x & y axis text labels
axis.text.x = element_text(color="black",size=10,hjust=1),axis.text.y = element_text(color="black"),axis.title.x=element_blank(),axis.title.y=element_blank(),plot.title=element_text(hjust=.5))+
ggtitle("Highest degrees attained by leadership")+
scale_x_discrete(labels= c("Other","Doctorate"))
pg_doc