使用R中的地图而不使用地理编码来绘制每个县的数据

时间:2018-08-17 17:38:17

标签: r maps plotly r-plotly

我有一些要使用ggplot2::map_data('county')进行可视化的数据。我的数据集中的位置信息仅限于州和县信息,即没有坐标。我尝试从> dput(rd2[1:10]) structure(list(utility_name = c("Arizona Public Service Co", "Arizona Public Service Co", "AES Alamitos LLC", "AES Huntington Beach LLC", "Los Angeles Department of Water & Power", "PSEG Power Connecticut LLC", "Tampa Electric Co", "Indianapolis Power & Light Co", "NRG Canal LLC", "Nantucket Electric Co"), plant_name = c("Ocotillo", "Ocotillo", "AES Alamitos LLC", "AES Huntington Beach LLC", "Scattergood", "Bridgeport Station", "Big Bend", "Eagle Valley (IN)", "Canal", "Nantucket"), state = c("AZ", "AZ", "CA", "CA", "CA", "CT", "FL", "IN", "MA", "MA"), county = c("Maricopa", "Maricopa", "Los Angeles", "Orange", "Los Angeles", "Fairfield", "Hillsborough", "Morgan", "Barnstable", "Nantucket"), current_year = c(2019, 2018, 2020, 2020, 2020, 2019, 2021, 2018, 2019, 2019), prime_mover = c("GT", "GT", "CT", "CT", "CT", "CT", "GT", "CT", "GT", "GT"), mw = c(485.7, 323.8, 462, 462, 230, 375.7, 784, 414, 330, 15.4)), .Names = c("utility_name", "plant_name", "state", "county", "current_year", "prime_mover", "mw"), class = c("data.table", "data.frame"), row.names = c(NA, -10L), .internal.selfref = <pointer: 0x0000000000120788>) 获取我所拥有的每个位置的坐标,但似乎不起作用:

数据:

library(data.table)
coord_data <- as.data.table(map_data('county'))
coord_data[subregion %in% unique(rd2$county)]

代码:

> coord_data[subregion %in% unique(rd2$county)]
Empty data.table (0 rows) of 6 cols: long,lat,group,order,region,subregion

输出:

subregion

也许map_data中的ggmap:geocode不是县名。有关如何绘制此图的任何建议?情节网站(countyscatterbubble)上的所有示例均具有精确的地理坐标。我不想使用{{1}},因为根据我过去的经验,即使我处于查询限制之内并且两次调用之间的时间大于指定的阈值,它也会经常失败。

0 个答案:

没有答案