在堆叠的条形图ggplot上粘贴%标签

时间:2020-06-16 18:32:07

标签: r ggplot2 geom-bar stacked-chart likert

我想在堆叠的条形图中添加%标签。这是我的数据。

discipline      <- c("Physician", "Social Worker", "NP/PA", "Case Manager", "Nurse", "Pharmacist", "Administrative"))
variable <- c("aware", "confident", "issue", "scope", "concerned", "access"))
response <- c("N/A", "Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree") 
Data      <- data.frame(discipline, variable, response)

这是我的代码,没有标签。

ggplot(incorporation)+
geom_bar(aes(fill = response, x = (..count..)/sum(..count..),
y = factor(reorder(variable,desc(response))),),
position = "fill")+
theme(axis.text.x = element_text(angle = -90, hjust = 0),
axis.title.y = element_blank(),
axis.title.x = element_blank())+
scale_fill_brewer(palette = "RdYlGn", direction = -1)+
scale_x_continuous(labels = scales::percent)

enter image description here

0 个答案:

没有答案