我是一名记者,致力于绘制 2002 年至 2012 年间黑人农民数量增加或减少的县的地图。我正在使用 R (3.2.3) 来处理和绘制数据。
我已经能够用一种颜色绘制整个县级收益和损失范围(从负 40 到正 165),但这使得我们很难看到收益和损失的模式。我想做的是使损失成为单一颜色(例如蓝色)的所有变体,并在第二种颜色(例如红色)的变体中渲染增益。
以下代码为发生正面和负面变化的县生成两个单独的(非常简化的)地图。有人知道如何在一张地图上以两种颜色捕获此信息吗?理想情况下,“差异”值为 0 的县将显示为灰色。谢谢你看这个!
df <- data.frame(GEOID = c("45001", "22001", "51001", "21001", "45003"),
Difference = c(-10, -40, 150, 95, 20))
#Second part: built a shapefile and join.
counties <- readOGR(dsn="Shapefile", layer="cb_2015_us_county_5m")
#Join the data about farmers to the spatial data.
counties@data <- left_join(counties@data, df)
#NAs are not permitted in qtm method, so let's replace them with zeros.
counties$Difference[is.na(counties$Difference)] <- 0
#Here are the counties that lost black farmers.
loss.counties <- counties[counties$Difference < 0, ]
qtm(loss.counties, "Difference")
#Here are the counties that gained black farmers.
gain.counties <- counties[counties$Difference > 0, ]
qtm(gain.counties, "Difference")