[R-sig-Geo] Problem plotting state borders
Éder Comunello
comunello.eder at gmail.com
Sat May 23 15:17:16 CEST 2015
Hi, José Luis!
Probably not! I tested (R console vs. R Studio) and got the same result.
Did you try update the packages? Could you paste your sessionInfo()
information in the next email?
================================================
Éder Comunello
PhD Student in Agricultural Systems Engineering (USP/Esalq)
Brazilian Agricultural Research Corporation (Embrapa)
Dourados, MS, Brazil [22 16.5'S, 54 49.0'W]
2015-05-23 7:39 GMT-04:00 José Luis Rotundo <rotundo.jose at gmail.com>:
> Hi Éder,
> Thanks a lot for your response. I cannot understand why this is happening.
> Using that exactly same code I end up with the map with straight-lined
> borders.
>
> It may have to do with me using R Studio instead of R??
>
> Thanks again,
> José
> El may 23, 2015 12:21 PM, "Éder Comunello" <comunello.eder at gmail.com>
> escribió:
>
>> Hello, José luis!
>>
>> I ran your code, but I did not notice the error reported. It's working
>> fine for me.
>>
>> sessionInfo()
>> R version 3.1.3 (2015-03-09)
>> Platform: x86_64-w64-mingw32/x64 (64-bit)
>> Running under: Windows 8 x64 (build 9200)
>>
>> locale:
>> [1] LC_COLLATE=Portuguese_Brazil.1252 LC_CTYPE=Portuguese_Brazil.1252
>> LC_MONETARY=Portuguese_Brazil.1252
>> [4] LC_NUMERIC=C LC_TIME=Portuguese_Brazil.1252
>>
>> attached base packages:
>> [1] stats graphics grDevices utils datasets methods base
>>
>> other attached packages:
>> [1] mapproj_1.2-2 maps_2.3-9
>>
>> loaded via a namespace (and not attached):
>> [1] tools_3.1.3
>>
>>
>> ================================================
>> Éder Comunello
>> PhD Student in Agricultural Systems Engineering (USP/Esalq)
>> Brazilian Agricultural Research Corporation (Embrapa)
>> Dourados, MS, Brazil [22 16.5'S, 54 49.0'W]
>>
>>
>> 2015-05-22 12:16 GMT-04:00 José Luis Rotundo <rotundo.jose at gmail.com>:
>>
>>> Dear List,
>>>
>>> I want to plot a US county level map with counties colored according a
>>> categorical variable. I was successful for the most part, but when
>>> trying to add state level borders, to make the map look better, the
>>> borders do not follow the geographical limits.
>>>
>>> Here is the link to the map I ended up with: http://imgur.com/UqcpVBW
>>>
>>> If you want to reproduce the what I am doing, the data is here:
>>> http://www.filedropper.com/data_4
>>>
>>> Below is the code I am using.
>>>
>>> Thanks a lot in advance for any help to solve this problem.
>>>
>>> José L. Rotundo
>>> CONICET
>>> Facultad de Ciencias Agrarias
>>> Univ. Nacional de Rosario
>>> Zavalla, Santa Fe
>>> Argentina
>>>
>>> #############################################################
>>> # Pick the colors for the categorical values
>>> colors = c("#CC0000", "#FF9999", "#E0E0E0", "#99FF99", "#00CC00")
>>>
>>> #Creates a new variable with the categories.
>>> data$colorBuckets <- as.numeric(cut(data$Slope, c(-0.30, -0.20, -0.10,
>>> 0.10,
>>> 0.20, 0.30)))
>>>
>>> # Put a 3 (equivalent to slope 0) when there is NA's
>>> data$colorBuckets[is.na(data$colorBuckets)] <- 3
>>>
>>> # Matches the values of FIPS with the color categories
>>> colorsmatched <- data$colorBuckets
>>>
>>> library(mapproj)
>>> # Map colored counties according the categories
>>> map("county", col = colors[colorsmatched], fill = TRUE, resolution = 0,
>>> lty = 0, projection = "polyconic")
>>>
>>> # Add border around each county
>>> map("county", col = "gray", fill = FALSE, add = TRUE, lty = 1, lwd = 0.2,
>>> projection = "polyconic")
>>>
>>> # Add border to each state (THIS IS THE PROBLEMATIC STEP)
>>> map("state", col = "black", fill = FALSE, add = TRUE, lty = 1, lwd = 0.4,
>>> projection = "polyconic")
>>>
>>> ################################################################
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>>
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list