2017-09-28 33 views
0

我在收缩plotOutput时遇到问题。我想要做的只是稍微收缩ggplot,因此盒子里有一点填充。在Shiny应用中缩放ggplot输出

这是我的形象:

enter image description here

这是我想要的形象:

enter image description here

的区别是微妙的,但基本上我只想缩小图形。

+1

也许[这](https://stackoverflow.com/questions/17838709/scale-and-size-of-plot-in-rstudio-shiny)可以帮助 – akrun

+0

是的,我看到了这,但它并没有给我我想要的:/ – Tarzan

回答

1

plotOutput中的width参数可用于该目的。然后你可以用中央对齐方式将输出包装在div中。

library(ggplot2) 
library(shiny) 

gg <- ggplot(mtcars, aes(wt, mpg)) + geom_point() + 
    theme(panel.background = element_rect(fill = 'grey')) 

shinyApp(
    fluidPage(
    plotOutput('plot1'), 
    div(
     plotOutput('plot2'), 
     style = "padding-right: 10%; padding-left: 10%" 
    ) 
), 
    function(input, output, session){ 
    output$plot1 <- renderPlot(gg) 
    output$plot2 <- renderPlot(gg) 
    } 
) 

enter image description here

+0

这不是我想缩小的整个面板,只是ggplot – Tarzan