[R-sig-Geo] Problem plotting state borders

José Luis Rotundo rotundo.jose at gmail.com
Sat May 23 17:15:37 CEST 2015


Hi Eder,

Thanks again for your effort. I ran again the script and got the same
straight lines as borders.

Here is my session info as you requested. I am new to R and GIS so do
not know how to interpret it.

R version 3.2.0 (2015-04-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] maptools_0.8-36  sp_1.1-0         mapproj_1.2-2    ggmap_2.4
[5] ggplot2_1.0.1    maps_2.3-9       data.table_1.9.4

loaded via a namespace (and not attached):
 [1] Rcpp_0.11.6         magrittr_1.5        MASS_7.3-40
munsell_0.4.2
 [5] colorspace_1.2-6    geosphere_1.3-13    lattice_0.20-31
rjson_0.2.15
 [9] jpeg_0.1-8          stringr_1.0.0       plyr_1.8.2
tools_3.2.0
[13] grid_3.2.0          gtable_0.1.2        png_0.1-7
digest_0.6.8
[17] RJSONIO_1.3-0       reshape2_1.4.1      stringi_0.4-1
RgoogleMaps_1.2.0.7
[21] scales_0.2.4        foreign_0.8-63      chron_2.3-45        proto_0.3-10


Cheers,

Jose.

PS. Thanks for the link on projections!





2015-05-23 10:17 GMT-03:00 Éder Comunello <comunello.eder at gmail.com>:
> 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
>>>
>>>
>



-- 

José L. Rotundo
CONICET
Facultad de Ciencias Agrarias
Univ. Nacional de Rosario
Zavalla, Santa Fe
Argentina



More information about the R-sig-Geo mailing list