R中的基本Choropleth状态图 [英] Basic Choropleth State Map in R

查看:140
本文介绍了R中的基本Choropleth状态图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很抱歉,因为我敢肯定这是一个基本问题.我要做的就是使用maps包在R中创建一个非常简单的Choropleth映射.这是我第一次尝试映射R中的任何数据.

I apologize because I am quite certain this is a basic question. All I want to do is create a very simple choropleth map in R using the maps package. This is my first attempt at mapping any data in R.

我的地理位置是包括DC在内的下48个州.这是我要绘制的数据集的前几行.

My geography is the lower 48 states including DC. Here are the first few rows of the dataset I want to plot.

> head(choro, n=7)
    AL     AR     AZ     CA     CO     CT     DC 
 "red"  "red"  "red" "blue" "blue" "blue"  "red" 

当我尝试绘制基本地图时:

When I attempt to plot a basic map:

map("state",
        regions = names(choro),
        lty = 1, lwd =1,
        boundary=TRUE,
        fill=TRUE,
        col=choro)

我看到的是附加的图像.我是R的新手,但我想未填充的状态不能正确合并,尽管我相信我使用的是标准"状态缩写.

The attached image is what I see. I am new to R, but I imagine the states that are not filled in did not merge correctly, although, I believe I am using 'standard' state abbreviations.

我在做什么错!/需要解决?

What am I doing wrong!/need to fix?

任何帮助将不胜感激.

推荐答案

如果您将regions = names(choro)取出,则会得到一个更完整的地图.如果要绘制Choro向量中可能缺少的项目,那么为什么不将白色"替换为颜色?如果您需要更完整的答案,请提供完整的choro副本.

If you take out the regions=names(choro), you will get a more completely filled map. If you want the items that are probably missing from the choro vector to be drawn then why not substitute "white" as the color? If you need a more complete answer then provide a full copy of choro.

choro <- c( "red",  "red",  "red" ,"blue" ,"blue", "blue",  "red")
require(maps)
data(state)
names(choro) <-names(state)[1:7]
map("state",  lty = 1, lwd =1,
        boundary=TRUE, fill=TRUE,
        col=choro)

请参阅附件图形:

这篇关于R中的基本Choropleth状态图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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