小编Jan*_*ane的帖子

格式化多个geom_sf图例

我正在ggplot中处理多个sf几何形状,并希望以点,线和正方形(对于多边形)的形式显示图例。但是,geom_sf图例结合了下面显示的我的几何特征(即结合线和点):

library(ggplot2)
library(sf)

poly1 <- cbind(lon = c(5, 6, 7, 5), lat = c(52, 53, 51, 52))

poly <- st_sf(st_sfc(st_polygon(list(poly1))))
line <- st_sf(st_sfc(list(st_linestring(cbind(lon = c(5.5, 4.5), lat = c(53.5, 54.5))))))
point <- st_sf(st_sfc(st_point(cbind(lon = 5.5, lat = 52.7))))

ggplot() +
  geom_sf(data = poly, aes(fill = "A")) +
  geom_sf(data = point, aes(colour = "B"), show.legend = "point") +
  geom_sf(data = line, aes(colour = "C"), show.legend = "line") +
  scale_fill_manual(values = c("A" = "yellow")) +
  scale_colour_manual(values = c("B" = "pink", "C" = …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 r-sf

5
推荐指数
1
解决办法
879
查看次数

单击Leaflet地图上的点以在Shiny中生成ggplot

我正在R中使用Shiny,试图创建一个Leaflet贴图,该贴图允许用户单击任何标记以生成代表该特定位置的信息(温度)的对应图。

我结合了这个问题的代码(单击传单地图上的点作为闪亮的图的输入)和此博客的第二个技巧(https://www.r-bloggers.com/4-tricks-for-working-使用-r-leaflet-and-shiny /),但似乎仍无法在Shiny中成功注册单击的标记点。

即,当我单击任何站点时,没有内容。

根据进一步的研究,我找不到任何解决方案,不胜感激。

library(leaflet)
library(shiny)
library(ggplot2)

# example data frame 
wxstn_df <- data.frame(Site = c("a", "a", "b"), Latitude = c(44.1, 44.1, 37), Longitude = c(-110.2, -110.2, -112.7), Month = c(1,2,1), Temp_avg = c(10, 18, 12))

ui <- fluidPage(column(7, leafletOutput("wsmap", height = "600px")),
  column(5, plotOutput("plot", height = "600px"))
)

server <- function(input, output) {

  # create a reactive value to store the clicked site
  stn <- reactiveValues(clickedMarker = NULL)

  ## leaflet map
  output$wsmap <- renderLeaflet({ …
Run Code Online (Sandbox Code Playgroud)

interactive r ggplot2 leaflet shiny

3
推荐指数
1
解决办法
1072
查看次数

标签 统计

ggplot2 ×2

r ×2

interactive ×1

leaflet ×1

r-sf ×1

shiny ×1