首页 > 解决方案 > 调整列大小后删除 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")
    
  })    

screen_shot_of_problem

标签: rggplot2shiny

解决方案


设法解决了(在花了很长时间之后:-)

在 ui 部分

plotOutput("share", height = 125)

推荐阅读