2017-09-28 55 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