简体   繁体   中英

Remove white space above and below ggplot2 plot after resizing columns

My geom_col() graph in a shiny app was too chunky so I reduced the column widths but then I was left with a massive gap between the two columns. I brought them close together with theme(aspect.ratio = 3/5). My remaining problem is the white space above and below the viz which are taking up space as part of the plot. How do I fix?

  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

Managed to work it out (after spending ages on it :-)

On ui section

plotOutput("share", height = 125)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM