网格中的多个传单

问题描述 投票:3回答:1

我有4个传单对象:A,B,C,D。我想用2×2网格绘制它们,但我一直很难尝试这样做。

我最初的想法是使用ggplot和facet_grid,但ggplot不知道如何处理类leaflet的对象。

我很感激你的帮助!

r ggplot2 leaflet r-grid
1个回答
3
投票

传单(或任何其他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)

从控制台渲染它。

使用Shiny流体页面布局

具有闪亮流体页面布局功能的示例:

library(shiny)

leaflet_grid_2 <- fluidPage(
  fluidRow(
    column(6, A), column(6, B) 
  ),
  fluidRow(
    column(6, C), column(6, D) 
  )
)

使用mapview

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

© www.soinside.com 2019 - 2024. All rights reserved.