r - 带有圆形条形图的填充面板
问题描述
我正在研究在网上找到的一些用于打印圆形条形图的代码块。我无法“缩放”或减少空白以获得更大的图表。我附上一张图片,我想至少在图表上方和下方减少区域(在红色区域中)。请问有什么提示吗?
带有红色“操纵”目标区域的图表:
ps抱歉代码乱七八糟,只是在试验......
source("code_wrang_eda_danger.R")
medie <- round(rowMeans(df_danger_Totals[, 2:12]), digits = 3)
tab1 <- cbind(df_danger_Totals,medie)
tab2 <-tibble::rowid_to_column(tab1, "id")
tab3 <- tab2 %>%
select(id, cer, medie)
label_data <- tab3
number_of_bar <- nrow(label_data)
angle <- 90 - 360 * (label_data$id-0.5) /number_of_bar
label_data$hjust<-ifelse( angle < -90, 1, 0)
label_data$angle<-ifelse(angle < -90, angle+180, angle)
p <- ggplot(tab3, aes(x=as.factor(id), y=medie)) +
geom_bar(stat="identity", fill=alpha("skyblue", 0.7)) +
# Limits of the plot = very important. The negative value controls the size of the inner circle, the positive one is useful to add size over each bar
ylim(-380,450) +
# Custom the theme: no axis title and no cartesian grid
#theme_minimal() +
theme(
axis.text = element_blank(),
axis.title = element_blank(),
panel.grid = element_blank(),
#plot.margin = margin(0.5, 0.50, 0.5, 0.5, "cm"),
plot.background = element_rect(fill = "white"),
panel.background = element_rect(fill = "red",
colour = "red"),
axis.ticks = element_blank(),
panel.spacing.x = unit(0.5, "lines"),
panel.spacing.y = unit(0.5, "lines"),
plot.margin = margin(t = 5, # Top margin
r = 5, # Right margin
b = 5, # Bottom margin
l = 5) # Left margin
) +
# This makes the coordinate polar instead of cartesian.
coord_polar(start = 0) +
# Add the labels, using the label_data dataframe that we have created before
geom_text(data=label_data, aes(x=id, y=medie+10, label=cer, hjust=hjust), color="black", fontface="bold",alpha=0.6, size=2.5, angle= label_data$angle, inherit.aes = FALSE )
p <- p + labs(title = "xxx",
subtitle = "xxx",
caption = "xxx") +
theme(
plot.title = element_text(hjust = 0.5, size = 14), # Center title position and size
plot.subtitle = element_text(hjust = 0.5), # Center subtitle
plot.caption = element_text(hjust = 0.5, face = "italic")# move caption to the left
)
ggsave(path = "charts","pog_waste_coll_2008_2018_danger_circ_barplot.png", width = 5, height = 5)
p
解决方案
推荐阅读
- workflow - 如何在 YouTrack 工作流程中获取问题类型
- asp.net - LINQ:获取引用列表不为空的最后一条记录 c#
- c - 为什么 Linux 内核中的 wait_event_interruptible() 从未在 while 循环中使用?
- sql - SQL 查询:在基表中输出并将聚合添加为额外的行
- mongodb - 从外部在 mongodb 容器中执行加载(文件)
- mysql - 错误 #1055 另一个包含非聚合列,该列在功能上不依赖于 GROUP BY 中的列
- css - 样式表新字体字体导入错误
- python - 令人沮丧的错误:在 Pandas 中创建新列时抛出 KeyError
- javascript - 如何在 JavaScript 中从 NodeList 中选择一个元素?
- python - 如何使用 python 将原始 CAN 数据转换为人类可读格式?