相关疑难解决方法(0)

如何将堆积百分比条形图标签居中

我试图绘制好的stacked percent barchart使用ggplot2.我已经阅读了一些材料,几乎可以设法绘制,我想要什么.另外,我附上材料,它可能在一个地方有用:

如何在不创建摘要数据框的情况下在ggplot2中标记堆积条形图?

创建堆叠的条形图,其中每个堆栈按比例缩放为100%

R堆积百分比条形图,包含二元因子和标签的百分比(使用ggplot)

我的问题是我不能放在labels我想要的地方- 在酒吧中间.在此输入图像描述

您可以在上面的图片中看到问题 - 标签看起来很糟糕,并且彼此重叠.

我现在正在寻找的是:

  1. 如何在酒吧(区域)的中间放置标签

  2. 如何绘制不是所有标签,但例如哪些标签超过10%?

  3. 如何解决重叠问题?

对于Q 1.@MikeWise建议可能的解决方案.但是,我仍然无法处理这个问题.

另外,我附上了可重复的例子,我是如何绘制这个grahp的.

library('plyr')
library('ggplot2')
library('scales')
set.seed(1992)
n=68

Category <- sample(c("Black", "Red", "Blue", "Cyna", "Purple"), n, replace = TRUE, prob = NULL)
Brand <- sample("Brand", n, replace = TRUE, prob = NULL)
Brand <- paste0(Brand, sample(1:5, n, replace = TRUE, prob = NULL))
USD <- abs(rnorm(n))*100

df <- data.frame(Category, Brand, USD)

# Calculate the percentages …
Run Code Online (Sandbox Code Playgroud)

r labels bar-chart ggplot2

22
推荐指数
1
解决办法
1万
查看次数

ggplot2 堆积条形图 - 每个条形图均为 100%,每个条形图内都有百分比标签

背景:我是 R 和 ggplot2 的新手,希望得到一个简单的答案,在相同的情况下可以让其他人受益。

问题:在 ggplot2 中使每个条形加起来为 100% 并在每个条形内显示百分比标签的简单方法是什么?

目标: 我想要的样子(每列总计 100%,每列内带有百分比标签)。

当前图表:这是我目前的条形图;基于“mtcars”数据集(它目前的样子)。下面我有“当前图表”:

library(ggplot2) # loads ggplot2
data <- mtcars # gets the mtcars dataset

#INFO: A simple barchart with X-axis being Nr of Cylinders, fill color indicating whether or not the car model has an Automatic gearbox..
# ..and Y-axis showing the count of cars by Nr of Cylinders
ggplot(mtcars, aes(x=cyl, fill = factor(am))) +
  geom_bar() +
  stat_count(geom …
Run Code Online (Sandbox Code Playgroud)

label r bar-chart ggplot2

4
推荐指数
3
解决办法
6171
查看次数

标签 统计

bar-chart ×2

ggplot2 ×2

r ×2

label ×1

labels ×1