【问题标题】:R shiny plot sizeR闪亮的情节大小
【发布时间】:2018-04-03 21:33:49
【问题描述】:

我有一个显示在框中的图,我想修改框的大小,但图比框大。如何修改它们,以便图保留并适合框?

#in ui.r
 box(
                  title = "Veniturile si cheltuielile",
                  status = "primary",
                  solidHeader = TRUE,
                  collapsible = TRUE,
                  plotOutput("ven_vs_chelt")
                )




#in server.r
 output$ven_vs_chelt <- renderPlot({
    ggplot(ven_ch, aes(x=ven_ch$ani_tot, y=ven_chelt, fill=tip)) +
      geom_bar(stat="identity", position=position_dodge(), colour="black") +
      xlab("An") + ylab("Valoare venituri si cheltuieli(lei)") +
      scale_fill_manual(values=c("#F78181", "#81F79F"))
  })

【问题讨论】:

  • 一些提示:1) 要获得响应,您应该使您的代码可重现,请参阅stackoverflow.com/questions/5963269/…。 2) 更一般地说,您正在寻找动态 UI 元素。因此,您应该查看renderUI()。如果您还有其他问题,请选择 1),我们可以提供帮助。

标签: r plot shiny


【解决方案1】:

您可以修改绘图的大小。这样它就可以装在盒子里了。您可以这样做来修改绘图大小:

## In your ui, set the width to 100% in your plotOutput
 plotOutput(outputId = "ven_vs_chelt",  width = "100%")

## In your server, you specify height and width to make a plot fit in your box. You should play with height and width. So that it would fit in the box.
output$ven_vs_chelt <- renderPlot({
ggplot(ven_ch, aes(x=ven_ch$ani_tot, y=ven_chelt, fill=tip)) +
  geom_bar(stat="identity", position=position_dodge(), colour="black") +
  xlab("An") + ylab("Valoare venituri si cheltuieli(lei)") +
  scale_fill_manual(values=c("#F78181", "#81F79F"))
}, height = 300, width = 450)

【讨论】:

  • 要响应,您需要获取窗口大小。我认为您应该通过这个问题来获得更多响应:Responsive Plot
猜你喜欢
  • 2017-08-12
  • 2014-09-12
  • 2016-03-25
  • 2019-08-15
  • 2016-12-23
  • 2021-05-10
  • 2016-10-12
  • 2018-02-08
  • 2015-11-16
相关资源
最近更新 更多