如何更改Shiny中ggplot元素的边距?

时间:2019-06-19 07:33:45

标签: r ggplot2 shiny

我在增加壁虱,小条等的边距时遇到麻烦。闪亮应用中的ggplotly对象的图像。
有人知道如何解决这个问题吗?是什么导致这种行为?

这是有关绘图的代码。该应用程序的所有其他部分均按预期工作。我的代码中没有可更改绘图区域大小的元素。

 output$graph <- renderPlotly({
 req(nrow(plotdata()) > 0)
 req(nrow(backgroundData()) > 0)

    background <- backgroundData() %>%
      plot_ly %>%
      ggplot()+
      geom_bar(mapping = aes(x = year, y = relValue), stat = 'identity')+
      xlim(1995,2017)+
      xlab("Jahr")+
      ylab("relative Werte")+
      facet_wrap(vars(type), nrow = 2, ncol = 2)

    background + geom_bar(plotdata(), mapping = aes(x = year, y = relValue, fill = subgroup)
                          , stat = 'identity')+
      scale_fill_manual(name = 'Legende', values = col_vector)+
      theme(
        axis.ticks.y = element_blank(),
        axis.text.y = element_text(margin = margin(r = 20)),
        legend.title = element_blank(),
        legend.margin = margin(50,50,50,50),
        panel.grid.major.x = element_blank(), #removes vertical grid-lines
        panel.spacing.y = unit(5, "pt"), #spacing between facets
        panel.spacing.x = unit(3, "pt"),
        strip.background = element_blank(), #removes facet titel background
        strip.text = element_text(size = 11, color = "black", face = "bold"), #changes facet titles 
        plot.margin = unit(c(0,0,0.5,1.8), 'cm') #margin of the whole plot element
      )

0 个答案:

没有答案