如何用R填充条形图

时间:2022-04-28 23:39:46

I don't speak English well.So please understand.I am trying to create a filled barplot, with percentages adding up to 100 for each fill. It is difficult to compare, Because each category has a different number. There are about 600 in O and about 6000 in Well_Sold. I want to make comparison easier. Specifically speaking About O of Well_Sold I want the sum of K and U in Publisher_ind to be 100 percent Similarly for X. I can not find a way to fill.So I figured out how to do facet_grid like this

我不会说英语。所以请理解。我正在尝试创建一个填充的条形图,每个填充的百分比加起来为100。很难比较,因为每个类别都有不同的数字。 O中约有600个,Well_Sold中约有6000个。我想让比较更轻松。具体来说,关于Well.Sold的O我希望Publisher_ind中K和U的总和为100%同样对于X.我找不到填充方法。所以我想出了如何做这样的facet_grid

library(ggplot2)

ggplot(game,aes(x=Publisher_ind,group=Well_Sold))+
geom_bar(aes(y=..prop..,fill=factor(..x..)),stat="count")+
geom_text(aes(label=scales::percent(..prop..),
              y=..prop..),stat="count",vjust=-.5)+
labs(y="Percent",fill="Publisher_ind")+
facet_grid(~Well_Sold)+
scale_y_continuous(labels=scales::percent)

如何用R填充条形图

But Other variables have 10 or more categories, This method is inconvenient. What I want is:

但是其他变量有10个或更多类别,这种方法很不方便。我想要的是:

如何用R填充条形图

Thank you very much for teaching me how.

非常感谢你教我如何。

1 个解决方案

#1


0  

I think what you want is a Grouped BarPlot: - https://www.statmethods.net/graphs/bar.html - (ggplot2) https://www.r-graph-gallery.com/48-grouped-barplot-with-ggplot2/

我想你想要的是一个Grouped BarPlot: - https://www.statmethods.net/graphs/bar.html - (ggplot2)https://www.r-graph-gallery.com/48-grouped-barplot-与-GGPLOT2 /

#1


0  

I think what you want is a Grouped BarPlot: - https://www.statmethods.net/graphs/bar.html - (ggplot2) https://www.r-graph-gallery.com/48-grouped-barplot-with-ggplot2/

我想你想要的是一个Grouped BarPlot: - https://www.statmethods.net/graphs/bar.html - (ggplot2)https://www.r-graph-gallery.com/48-grouped-barplot-与-GGPLOT2 /