删除ggplot map / choropleth中的边界线 [英] Remove border lines in ggplot map/choropleth

查看:180
本文介绍了删除ggplot map / choropleth中的边界线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除ggplot中生成的choropleth的区域之间的连线。我的问题是由非常大的非常小的区域(人口普查区块组)的非常大的地图驱动的,这些地区数量众多,无法根据边界的密度看到填充形状的颜色。我正在使用ggplot2版本1.0.0在Mac上使用更新的RStudio;在Windows上似乎也没有发生同样的问题。

以下是每个县都有不同颜色的示例(使用县),因此边界不是必需的。第一个使用紫色边框来强调。第二种是color = NA,这是我试图消除所有边界的不成功。

  library(ggplot2)
图书馆(地图)
tn = map_data(县,地区=田纳西州)
ggplot(tn,aes(x = long,y = lat,group = group))+
geom_polygon(aes(fill = group),color =purple)

  ggplot(tn,aes(x = long,y = lat,group = group))+ 
geom_polygon(aes(fill = group),color = NA)
pre>

解决方案

另一个选项是将fill和color设置为等于group,这对macOS起作用我试过了:

  library(ggplot2)
library(maps)
tn = map_data(county,region =Tennessee )
ggplot(tn,aes(x = long,y = lat,group = group))+
geom_polygon(aes(fill = group,color = group))

输出:




I would like to remove the lines between regions of a choropleth generated in ggplot. My question is motivated by a very large map with very very small regions (census block groups) that are so numerous that it's impossible to see the color filling the shape given the density of the borders. I'm using updated RStudio on a Mac with ggplot2 version 1.0.0; the same problem does not seem to occur on Windows.

Here are examples (using counties) that have different colors for each county so that the borders are not necessary. The first uses purple borders for emphasis. The second has color = NA which was my unsuccessful attempt to eliminate all borders.

library("ggplot2")
library("maps")
tn = map_data("county", region = "tennessee")
ggplot(tn, aes(x = long, y = lat, group = group)) + 
  geom_polygon(aes(fill = group), color = "purple")

ggplot(tn, aes(x = long, y = lat, group = group)) + 
  geom_polygon(aes(fill = group), color = NA)

解决方案

Another option is to set both fill and color equal to group, which worked on the macOS I tried it on:

library("ggplot2")
library("maps")
tn = map_data("county", region = "tennessee")
ggplot(tn, aes(x = long, y = lat, group = group)) + 
  geom_polygon(aes(fill = group, color = group))

Output:

这篇关于删除ggplot map / choropleth中的边界线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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