如下图所示,当在侧栏中选择多个县时,我的图的高度保持不变。这使图太拥挤,以致标签变得不可读。我想根据侧边栏中选择的县数来更改图的高度。我怎样才能做到这一点?
在下面,请查看我认为需要修改的部分代码。
mainPanel(plotOutput("workforce_plot"),
workforce_plot <- reactive({
ggplot(workforce_data(), aes(x =Age_Group, y = Percentage, fill=County.y)) +
geom_bar(stat = "identity",position = position_dodge()) +
geom_text(
aes(label = Percentage2),
vjust = 0.5,
colour = "black",
position = position_dodge(width=0.9),
fontface = "bold",
size=3.2,
hjust = 0)+
ylim(0,110)+
coord_flip()+
labs(
x = "Age Groups",
y = "Percentage",
face = "bold")
})
output$workforce_plot <- renderPlot ({
workforce_plot()
})
您可以height
在renderPlot
函数中添加参数,然后将其传递给函数,该函数根据一些相关的反应来调整高度。
一个例子:
output$workforce_plot <- renderPlot ({
workforce_plot()
}, height = function() {200 + (length(workforce_data()[["County.y]]) *.2)})
(也可能是类似length(input$country)
反应式expr的东西。)
然后在该面板中ui.R
定义height = 'auto'
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句