首页 > 解决方案 > 如何根据少数国家的计数(n)大小绘制带有一些圆圈的世界地图,这些国家的传单在 R 中?

问题描述

我提前道歉,但我真的很难尝试使用leaflet库在 R 中做一个简单的地图绘图。对于这样一个简单的问题,这可能是最基本的问题,但我希望将世界地图作为输出,其中这些国家的圆圈相对于 n 大小。这是我的输入数据:

country_groups <- structure(list(country_name = c("Australia", "Brazil", "Canada", 
"China", "Germany", "India", "Japan", "Korea, Republic of", "Romania", 
"Russian Federation", "Spain", "Taiwan, Province of China", "United Kingdom of Great Britain and Northern Ireland", 
"United States of America"), latitude = c(47.516231, -14.235004, 
56.130366, 35.86166, 51.165691, 20.593684, 36.204824, 35.907757, 
45.943161, 61.52401, 40.463667, 23.69781, 55.378051, 37.09024
), longitude = c(14.550072, -51.92528, -106.346771, 104.195397, 
10.451526, 78.96288, 138.252924, 127.766922, 24.96676, 105.318756, 
-3.74922, 120.960515, -3.435973, -95.712891), n = c(2L, 1L, 1L, 
541L, 1L, 6L, 3L, 6L, 1L, 3L, 1L, 3L, 1L, 56L)), row.names = c(NA, 
-14L), class = "data.frame")

这是我尝试过的,但我得到non-numeric argument for binary operator了一个错误。

country_groups$n <- as.integer(country_groups$n)
country_groups$longitude <- as.numeric(country_groups$longitude)
country_groups$latitude <- as.numeric(country_groups$latitude)

leaflet(country_groups)%>%
  addCircles(lng = ~longitude, lat = ~latitude, weight = 1,
             radius = n * 30, popup = ~country_name
  )

当我尝试as.numeric(n)在图形函数内部使用时,它会删除它Error in as.numeric(n) : cannot coerce type 'closure' to vector of type 'double'

标签: rleafletworld-map

解决方案


推荐阅读