[R-sig-Geo] plotting counties of two states

Sarah Goslee sarah.goslee at gmail.com
Mon Jun 17 14:56:42 CEST 2013


Hi,

On Sun, Jun 16, 2013 at 10:46 PM, Milan Sharma
<milansharma2012 at yahoo.com> wrote:
> Hi all,
> As I already mentioned, this is the problem due to one extra county "yellowstone national" in montana. I am trying to plot Montana and wyoming together for further analysis.. At the last line, index does not match between  counties$names and data$co(see NA below). I know this is is due to the extra county of montana. I would appreciate any help in this.

Well, what do you want to have happen for Yellowstone National Park?

You could import your own shapefile with the county boundaries you
expect, you could insert NA values into your data for YNP, you could
modify the file that you're using to remove that entry. And so on.
There's not an extra county, but there is an extra-county geographic
area. You need to decide what the best way for your purposes is to
handle that.


> I attached data if u want to have a look.

The server blocks most attachments, and dput() is the best way to
provide data as part of a reproducible example.

> library(maps)
> data<-read.csv("2data.csv",header=TRUE)
>  dim(data)#79 rows
> [1] 79  6
> data[1,]#first row
>     state     county        Y        X Longitude Latitude
> 1 Montana Beaverhead 5.393363 7.893883 -112.8929 45.13386
>  data$co <- paste(tolower(data$state),tolower(data$county), sep='.')
>  counties <- map("county",c("montana","wyoming"), fill=T, plot=F)
>  commaReplace <- function(x) {
> + return(gsub(",",".", x))
> + }
>  counties$names <- sapply(counties$names, commaReplace, simplify=TRUE)
>  names(counties$names) <- NULL
>  length(counties$names)
> [1] 80
>  index <- match(counties$names,data$co)
>  index
>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
> [26] 26 27 29 28 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
> [51] 51 52 53 54 55 56 NA 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
> [76] 75 76 77 78 79
> #####
> Thanks in advance,
> Milan
>


-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-sig-Geo mailing list