Kerr McIntosh
Kerr McIntosh

Reputation: 131

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

Upvotes: 1

Views: 343

Answers (1)

Kerr McIntosh
Kerr McIntosh

Reputation: 131

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

On ui section

plotOutput("share", height = 125)

Upvotes: 1

Related Questions