我試圖在我的Shiny應用程序的主面板中顯示多個圖。R中的多個圖Shiny
我使用從R cookbook
multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) {
library(grid)
# Make a list from the ... arguments and plotlist
plots <- c(list(...), plotlist)
numPlots = length(plots)
# If layout is NULL, then use 'cols' to determine layout
if (is.null(layout)) {
# Make the panel
# ncol: Number of columns of plots
# nrow: Number of rows needed, calculated from # of cols
layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
ncol = cols, nrow = ceiling(numPlots/cols))
}
if (numPlots==1) {
print(plots[[1]])
} else {
# Set up the page
grid.newpage()
pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))
# Make each plot, in the correct location
for (i in 1:numPlots) {
# Get the i,j matrix positions of the regions that contain this subplot
matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))
print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,
layout.pos.col = matchidx$col))
}
}
}
的的multiplot功能,然後調用的multiplot
multiplot(p1,p2,p3,p4,p5,p6, cols=1)
但它看起來像它試圖在到主面板
壓扁一切這裏就是我的應用程序看起來像只有一個情節
這裏是我的ui.R
shinyUI(fluidPage(
titlePanel("Baseball"),
sidebarLayout(
sidebarPanel(
selectInput(
"var", label = "Choose a group to visualize",
choices =c(Overall = "overall", Offense = "offense", Pitchers = "pitchers", Simpsons = "simpsons"),
selected = "offense")
),
mainPanel(
plotOutput("plotOffense")
)
)
)
)
我需要使用的東西,而不是mainPanel中,允許更多的圖形放置在瀏覽器中?
你有一個HTML容器,你正在放置你的陰謀.''ultilot'與它的大小無關。您可能會滿意於簡單地增加此容器的高度,即plotOutput(「plotOffense」,height =「800px」)'。你可以讓這個更「程序化」,但它可能需要深入鑽研。 – jenesaisquoi
,但一個更簡單的解決方案是不使用'多功能'功能,併爲每個圖形單獨製作'renderPlot'和'plotOutput'。 – jenesaisquoi
@bunk謝謝,我會考慮改變身高。你的第二個評論是我的備份計劃。但這些圖將取決於用戶在下拉列表中選擇的內容。我必須找出一種方法來捕獲UI中的用戶輸入.R – rvisio