基于mapview中不同变量的点颜色和符号大小 [英] Point color and symbol size based on different variables in mapview

查看:60
本文介绍了基于mapview中不同变量的点颜色和符号大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在mapview中使用不同比例的主题,以帮助可视化收益与损失,其中包括:

I'm trying for a divergent scale theme in mapview to help visualize gains vs. losses, with:

  • 以绝对值比例标出符号圈的大小(以突出显示损失与收益一样多)
  • 圆圈的不同色阶填充(例如,深蓝色> blue>白色>红色>深红色表示大多数负数>负数>零>正数>最大)
  • 将鼠标悬停在保留原始值的悬停标签上

有什么想法吗?

library(tidyverse)
library(mapview)
library(sf)

lat <- rep(34,16)
lon <- seq(-128, -126, length = 16)
value <- c(-1000, -800, -600, -400, -200, -100, -50, 
            -25, 25, 50, 100, 200, 400, 600, 800, 1000)

#make data.frame
df <- data.frame(lat, lon, value) 

#make spatial object for mapview
df <- st_as_sf(df, coords = c("lon", "lat"), crs = 4326) %>%
      mutate(value_abs = abs(value)) #value_abs intended for `cex` argument

pal <-  mapviewPalette("mapviewSpectralColors") #from mapview doc. example
m   <-  mapview(df["value"], #sets hover over value as this column
         cex = "value",      #sets circle diameter scaling on this column
         legend = TRUE,
         col.regions = pal(100), #closest I found to a red-blue divergent scale
         layer.name = "value")  
m

换句话说,我希望下面的点的图案与左侧对称,大小与右侧相同,但左侧有蓝色圆圈,右侧有红色圆圈,并且仍然允许用户可以通过鼠标悬停查看实际(非绝对)值(例如 -1000 ).

In other words, I'm hoping for the pattern of points here below to be symmetrical with the left side as a mirror image of the right in size, but with blue circles at left, red at right, and still allowing the user to see the actual (non absolute) values (e.g. -1000) by mouseover.

尝试:将 cex ="value" 切换为 cex ="value_abs" 会产生警告:在min(x)中:没有min不可缺少的参数;返回Inf 而不绘制任何点,或者返回 cex = df $ value_abs (不带引号),这使无色的,巨大的点成为可能.我不打算需要两个图例-只需一个用于圆圈大小或填充的图例,就可以像现在一样显示最小值和最大值,就很好了.

attempts: switching cex = "value" with cex = "value_abs" yields warning: In min(x) : no non-missing arguments to min; returning Inf without any points drawn, or with cex = df$value_abs (no quotes), which makes uncolored, enormous points. I'm not planning on needing two legends - just one for either the circle size or fill, showing a min and max value like it does now, would be great.

推荐答案

您非常亲密.您需要明确引用 df $ value_abs .看下面:

You are very close. You need to explicitly refer to df$value_abs. Look below:

library(tidyverse)
library(mapview)
library(sf)

df <- data.frame(lat=rep(34,16), 
                 lon=seq(-128, -126, length = 16), 
                 value=c(-1000, -800, -600, -400, -200, -100, -50, 
                         -25, 25, 50, 100, 200, 400, 600, 800, 1000)) 

df <- st_as_sf(df, coords = c("lon", "lat"), crs = 4326) %>%
               mutate(value_abs = abs(value))

pal <-  mapviewPalette("mapviewSpectralColors")

mapview(df["value"], 
                cex = df$value_abs/100, 
                legend = TRUE,
                col.regions = pal(100), 
                layer.name = "value")  

reprex软件包(v0.3.0)于2019-06-24创建

Created on 2019-06-24 by the reprex package (v0.3.0)

这篇关于基于mapview中不同变量的点颜色和符号大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆