这已经相当接近了:
# 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"))
几个解释:
- 我们分别使用
position = "dodge2"(请注意,这需要ggplot_ggplot2_3.0.0,否则使用position = position_dodge(width = 1.0))和position = position_dodge(width = 0.9),使用躲避的条形和匹配的躲避标签。
- 我们使用
facet_wrap 并强制采用单列布局;条形标签移至底部。
- 我们使用
coord_flip(expand = F) 旋转整个绘图,其中 expand = F 确保左对齐 (hjust = 0) 刻面条文本与 0 对齐。
- 最后我们调整了主题以增加整体审美相似性。