堆积百分比条形图ggplot2

stacked percent bar chart ggplot2

我有一个具有以下数据格式的 csv 文件

963669136  solved   lost_village desc
948902923  rejected donations      desc
208285984  open     lost_village   desc
208285984  solved   lost_village   desc
268433965  solved   lost_village   desc
464273209  open     feedback       desc
464273209  solved   feedback       desc
2571706944 solved   victory_points desc

我通过以下方式获取信息

tickets = read.csv("~/materials/minor/hw02/data/tickets_new.csv")

我想制作堆积百分比条形图。 但是,我只能做到这一点:

ggplot() +  
geom_bar(data = game_tag, aes(x = tag, fill = status)) +
  coord_flip() 

The Bar chart I get 我怎样才能使它成为 y 的百分比而不是计数。 我希望结果看起来像那样

Like that that

非常感谢任何帮助!!谢谢!!

您可以使用包 scales。这应该有效:

library(scales)

ggplot() +  
geom_bar(data = game_tag, aes(x = tag, fill = status), position="fill") +
coord_flip() +
scale_y_continuous(labels = percent_format())