RMarkdown中flexdashboard仪表盘如何调整布局扩大热图展示区域
解决方案
你可以通过调整布局结构、自定义行高、优化热图渲染参数三个维度实现需求,具体修改如下:
核心修改点
- 删除页面开头无内容的空Row:你现有代码中Page2标题下的第一个Row块没有任何内容,正是它占用了你说的灰色空白区域,直接删除该空Row定义即可回收这部分空间
- 给热图所在Row添加
data-height属性,自定义分配更大的垂直显示空间,数值可根据需求调整 - 给热图的渲染代码块添加
fig.width、fig.height参数,同时在renderPlot中指定height参数,让热图撑满分配的容器空间
修改后完整代码
Page 2 ======================================================================= Inputs {.sidebar} ----------------------------------------------------------------------- ```{r global1, include=FALSE} # load data in 'global' chunk so it can be shared by all users of the dashboard library(biclust) data(BicatYeast) set.seed(1) res <- biclust(BicatYeast, method=BCPlaid(), verbose=FALSE)
selectInput("clusterNum", label = h3("Cluster number"), choices = list(" I01" = 1, " I02" = 2, " I03" = 3, "4" = 4, "5" = 5), selected = 1)
Microarray data matrix for 80 experiments with Saccharomyces Cerevisiae
organism extracted from R's biclust package.
Sebastian Kaiser, Rodrigo Santamaria, Tatsiana Khamiakova, Martin Sill, Roberto
Theron, Luis Quintales, Friedrich Leisch and Ewoud De Troyer. (2015). biclust:
BiCluster Algorithms. R package version 1.2.0.
http://CRAN.R-project.org/package=biclust
Row {data-height=600}
Heatmap
num <- reactive(as.integer(input$clusterNum)) col = colorRampPalette(c("red", "white", "darkblue"), space="Lab")(10) renderPlot(height = 550, { p = par(mai=c(0,0,0,0), mar=c(0,0,0,0)) heatmapBC(BicatYeast, res, number=num(), xlab="", ylab="", order=TRUE, useRaster=TRUE, col=col) par(p) })
Row {.tabset}
Parallel Coordinates
renderPlot( parallelCoordinates(BicatYeast, res, number=num()) )
Data for Selected Cluster
# only display table for values in cluster 4 renderTable( BicatYeast[which(res@RowxNumber[, num()]), which(res@NumberxCol[num(), ])] )
## 参数调整说明 你可以根据实际显示效果修改`data-height`的数值、代码块的`fig.width`/`fig.height`参数、`renderPlot`中的`height`参数,直到热图大小符合你的预期。 --- 内容的提问来源于stack exchange,提问作者silent_hunter
相关产品推荐
相关产品推荐

