这种情节可以用ggplot2完成吗?

use*_*933 4 r bar-chart ggplot2

我正在使用Rggplot2为出版目的做一些情节.我遇到过这个情节,我想用它来复制它ggplot2.但是,我从未见过像这样的情节ggplot2.

可以用ggplot2吗?酒吧下方的文字怎么样?我想这些必须在ggplot2代码中进行硬编码.你如何调整这些文字?

条状图

Mau*_*ers 9

这相当接近:

# Generate sample data (I'm too lazy to type out the full labels)
df <- data.frame(
    perc = c(60, 36, 44, 41, 42, 57, 34, 52),
    type = rep(c("blue", "green"), 4),
    label = rep(c(
        "Individual reports created as needed",
        "Regular reports on single topics",
        "Analytics using data integrated from multiple systems",
        "Business unit-specific dashboards and visuals"), each = 2))


library(ggplot2)
ggplot(df, aes(1, perc, fill = type)) +
    geom_col(position = "dodge2") +
    scale_fill_manual(values = c("turquoise4", "forestgreen"), guide = FALSE) +
    facet_wrap(~ label, ncol = 1, strip.position = "bottom") +
    geom_text(
        aes(y = 1, label = sprintf("%i%%", perc)),
        colour = "white",
        position = position_dodge(width = .9),
        hjust = 0,
        fontface = "bold") +
    coord_flip(expand = F) +
    theme_minimal() +
    theme(
        axis.title = element_blank(),
        axis.text = element_blank(),
        axis.ticks = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        strip.text = element_text(angle = 0, hjust = 0, face = "bold"))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

一些解释:

  1. 我们使用躲避条和匹配的躲闪标签position = "dodge2"(注意这需要ggplot_ggplot2_3.0.0,否则使用position = position_dodge(width = 1.0))和position = position_dodge(width = 0.9).
  2. 我们使用facet_wrap并强制使用单列布局; 条带标签移动到底部.
  3. 我们用整个绘图旋转coord_flip(expand = F),expand = F确保左对齐(hjust = 0)小平面条文本与0对齐.
  4. 最后,我们调整主题以增加整体美学相似性.