我有4个传单对象:A,B,C,D。我想用2×2网格绘制它们,但我一直很难尝试这样做。
我最初的想法是使用ggplot和facet_grid,但ggplot不知道如何处理类leaflet的对象。
我很感激你的帮助!
传单(或任何其他htmlwidgets)可以与htmltools::tagList
结合使用。
在这种情况下,一个简单的html table
可以处理布局:
library(htmltools)
leaflet_grid <-
tagList(
tags$table(width = "100%",
tags$tr(
tags$td(A),
tags$td(B)
),
tags$tr(
tags$td(C),
tags$td(D)
)
)
)
您可以将leaflet_grid
直接放入knitr chunk或使用
browsable(leaflet_grid)
从控制台渲染它。
具有闪亮流体页面布局功能的示例:
library(shiny)
leaflet_grid_2 <- fluidPage(
fluidRow(
column(6, A), column(6, B)
),
fluidRow(
column(6, C), column(6, D)
)
)
library(mapview)
要在所有面板上同步缩放,请使用sync
:
sync(A, B, C, D)
而latticeView
将创建没有同步的面板
latticeView(A, B, C, D)
(见https://r-spatial.github.io/mapview/articles/articles/mapview_05-extras.html)