【发布时间】:2021-09-19 03:51:33
【问题描述】:
我的下图在子图之间有填充或填充到顶部/底部或左侧/右侧,具体取决于应用程序窗口的大小。我对这里发生的间距和布局管理非常满意,并且希望随着绘图数量的增长或缩小(或应用程序窗口调整大小)保持灵活性以动态调整大小。但是,我希望此填充的背景颜色与应用程序的灰色背景相同,而不是白色。
library(dplyr)
library(ggplot2)
library(ggcorrplot)
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
ui <- dashboardPage(
header = dashboardHeader(),
sidebar = dashboardSidebar(),
body = dashboardBody(
fluidRow(
plotOutput("test", width = '100%'), align="center"
)
)
)
server <- function(input, output) {
#generate some dummy data with a random number of plots to show
set.seed(NULL)
numPlots <- sample(1:5, 1)
plot <- sort(rep(seq(1:numPlots), 10))
d <- data.frame(A = runif(10*numPlots, 0, 10), B = runif(10*numPlots, 0, 10), C = plot)
matchingGray <- rgb(236/255, 240/255, 245/255) #best guess using screenshot and then dropper in another tool
g <- list()
for (p in 1:numPlots)
{
g[[p]] <- ggcorrplot(corr = cor(d %>% filter(C == p) %>% select(A,B))) +
theme(plot.background = element_rect(fill = matchingGray, linetype = "blank"))
}
output$test <- renderPlot({
gridExtra::grid.arrange(grobs = g, ncol = length(g))
})
}
shinyApp(ui = ui, server = server)
忽略给出无意义相关性的愚蠢数据,这只是一个简单的占位符,可以解决问题的核心。拥有可变数量的子图是关键......尝试多次运行应用程序以查看对填充的影响。谢谢!
【问题讨论】:
标签: r shiny colors background