r - 调整列大小后删除 ggplot2 图上方和下方的空白
问题描述
我在一个闪亮的应用程序中的 geom_col() 图表太厚实了,所以我减小了列宽,但随后我在两列之间留下了巨大的差距。我将它们与主题(aspect.ratio = 3/5)紧密结合在一起。我剩下的问题是可视化上方和下方的空白区域,它们占用了空间作为情节的一部分。我该如何解决?
output$share <- renderPlot({
filtered_year() %>%
ggplot() +
aes(x = candidate, y = votes_perc, fill= party) +
geom_col(position = "dodge", width=0.75) +
labs(x = "") +
theme_light() +
theme(axis.title.x = element_blank(),
axis.text.y = element_text(size = 12, margin=margin(0,0,0,0)),
axis.text.x = element_blank(),
legend.position = "none",
line = element_blank(),
panel.border = element_blank(),
aspect.ratio = 3/5) +
scale_fill_manual(values = c("#5390D9", "#D90429")) +
coord_flip() +
geom_text(aes(label = paste0(votes_perc,"%")), position = position_stack(vjust = 0.8), size = 8 ,colour = "#ffffff")
})
解决方案
设法解决了(在花了很长时间之后:-)
在 ui 部分
plotOutput("share", height = 125)
推荐阅读
- c++ - SIMD:实现 _mm256_max_epu64_ 和 _mm256_min_epu64_
- java - 比较两个列表并分配到新的对象列表中
- docker - Apache Oozie 可以运行 docker 容器吗?
- zooming - Plotly 双击 unzoom 对我不起作用
- c++ - 分配器和重新绑定如何与容器一起使用?
- excel - Excel VBA函数确定行号
- javascript - 是否可以在直播视频上添加过滤器?
- javascript - 如何在右侧对齐垂直轴?
- php - 需要帮助从 md5 更新到 sha-512 Authorize.net
- c - 如何同时正确使用管道和信号?