use*_*933 4 r bar-chart ggplot2
我正在使用R并ggplot2为出版目的做一些情节.我遇到过这个情节,我想用它来复制它ggplot2.但是,我从未见过像这样的情节ggplot2.
可以用ggplot2吗?酒吧下方的文字怎么样?我想这些必须在ggplot2代码中进行硬编码.你如何调整这些文字?
这相当接近:
# 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)
一些解释:
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对齐.| 归档时间: |
|
| 查看次数: |
198 次 |
| 最近记录: |