Wednesday 15 June 2011

r - How do I combat "Error in Polygon" error message when trying to find centroid for map labeling? -


I am trying to fill the counties of states with data for help in that project on which I am working I am I found an amazing answer to add a county name to the county map of New York. I was able to use it to help it in some states, but when I try to use the maps of Texas and Louisiana, I am striking. For reference, this is what I am writing:

  Library (ggplot2) library (SP) library (map) getLabelPoint & lt; - Function (County) {Polygon (County [c ('long', 'Let' ']]) @ Lept} df & lt; - map_data ('County', 'Louisiana') Centroid & lt; Error in polygon outside (county [c ("long", "late")]: not ring off (by df, df, $ subregion, getLabelPoint)   

"

I honestly do not even know where to start to fix it, so any help or an alternative way would be too horrible.

Problem data is generated by frames partitions by trying by wrong variable Instead of using sapply group , sub-prime (see end of post), should not be used. > Instead? I think it gives good formatted and more easily usable output:

  t (sapply (unique (df $ group), function (x) polygon (df [df $ group == x, c ("long", "late")]) @ lap # [, 1] [, 2] # [1,] -92.40716 30.2 9 9 # [2,] -92.82364 30.65532 # [3 ,] -90.91371 30.20234 # [4,] -91.06610 29.90319 # [5,] -92.00565 31.08009 # [6,] -93.34896 30.65511 # ..........   

Edit

The problem was easier than I imagined! You were splitting on the wrong group variable, this group no sub-rule Should be , Better solution for placing labels than strange formatting by my solution by (IMHumbleO)

  centroids & lt; - (df, df $ group) GetLabelPoint).    

No comments:

Post a Comment