小编etn*_*bal的帖子

如何在ggplot中实现绝对百分比?

我正在尝试使用 gpplot 在堆叠图中绘制正数和负数。根据我在此页面上找到的示例,这工作正常。

我的图表的限制是 -1 和 1,但我希望比例尺将标签显示为绝对百分比,即从左侧的 100% 到中心的 0% 到右侧的 100%。

下面的最小示例说明我可以获得百分比刻度标签 ( labels = percent) 或绝对刻度 ( labels = abs),但我不知道如何组合它们。

提前致谢。

library(tidyverse)
library(scales)

x <- tribble(
  ~response, ~count,
  "a",         -0.2,
  "b",         -0.1,
  "c",          0.5,
  "d",          0.2
)

p <- ggplot() +
  geom_bar(data = x,
           aes(x = "", y = count, fill = response),
           position = "stack",
           stat = "identity") +
  coord_flip()

# Percent scale
p + scale_y_continuous(labels = percent, limits = c(-1, 1), expand = c(0.05, …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

7
推荐指数
1
解决办法
588
查看次数

标签 统计

ggplot2 ×1

r ×1