0

I'm using a ggplot chart with geom_tile in RShiny. When I select a category with fewer y-axis elements, the tiles increase in height. I'd like to fix the tile height so that the chart height decreases when there are fewer y-axis elements, code below:

 ggplot(selected_data(), aes(week, zone, fill= value, text=text)) + 
                scale_y_discrete(limits = unique(rev(selected_data()$zone))) + 
                geom_tile(aes(fill = value)) +
                geom_text(aes(label = format(round_half_up(value,digits = 1), nsmall = 1)), size=4) +
                labs(x="Week", y="") + 
                scale_x_discrete(position = "top") +
                scale_fill_viridis(option = "viridis") +
                theme_grey(base_size = 16) + labs(fill = "Rate per\n1,000 population") +
                theme(legend.position = "top")
Adam
  • 1
  • 1
  • 1
    Hi Adam! You need to provide a reproducible example. Check out how to ask a question: https://stackoverflow.com/help/how-to-ask – Edo Aug 28 '20 at 08:28
  • 1
    The height of the chart is determined by the plotting device. In case of shiny it is determined by plotOutput//renderPlot. See https://mastering-shiny.org/action-graphics.html#dynamic-height-and-width on how to dynamically adjust the chart height. – stefan Aug 28 '20 at 09:50

0 Answers0