
Hi,

I am trying to map US migration from IRS files using great circles.  The IRS provides two files (either state or county level) 
for origin and destination in and out of the state or county. The code thus far gives me a spatialpolygonsdataframe:

> str(county)
Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots
  ..@ data       :'data.frame': 3258 obs. of  15 variables:
  .. ..$ area           : num [1:3258] 0.00303 0.13356 0.00267 0.74387 0.93214 ...
  .. ..$ perimeter      : num [1:3258] 0.257 2.05 0.247 5.424 6.036 ...
  .. ..$ co99_d00_      : num [1:3258] 1088 1277 157 158 159 ...
  .. ..$ co99_d00_i     : num [1:3258] 1087 1276 156 157 158 ...
  .. ..$ state          : Factor w/ 49 levels "01","04","05",..: 38 37 46 25 46 26 22 49 46 46 ...
  .. ..$ county         : Factor w/ 301 levels "001","003","005",..: 6 52 33 48 5 65 43 25 41 41 ...
  .. ..$ name           : Factor w/ 1799 levels "Abbeville","Acadia",..: 1704 1094 1486 1387 303 1040 899 1646 1730 1730 ...
  .. ..$ lsad           : Factor w/ 5 levels "06","08","09",..: 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ lsad_trans     : Factor w/ 3 levels "city","County",..: 2 2 2 2 2 2 2 2 2 2 ...
  .. ..$ fips           : chr [1:3258] "44009" "42091" "53057" "30085" ...
  .. ..$ m_0910_in_dest : int [1:3258] NA NA NA NA NA 58798 NA NA NA NA ...
  .. ..$ m_0910_in_orig : int [1:3258] NA NA NA NA NA 58803 NA NA NA NA ...
  .. ..$ m_0910_out_dest: int [1:3258] 3472 3054 3209 58014 3269 59154 51486 3505 2117 2117 ...
  .. ..$ m_0910_out_orig: int [1:3258] 84440 83024 106089 58018 104703 59149 51481 110502 106622 106622 ...
  .. ..$ labpt          : num [1:3258, 1:2] -71.6 -75.4 -122.6 -105 -120.6 ...
  .. ..- attr(*, "data_types")= chr [1:9] "N" "N" "N" "N" ...
  ..@ polygons   :List of 3258

I  used the following to extract the long/lat of the label point @labpt to use as startpoints or endpoints for the great circle lines
depending on whether they were dest(ination) or orig(in) and dest or orig was not NA.

## reach down to the @labpt level of county using ggplot2 and gpclib to 
## get coordinates of county label points to use as start and endpoints
## for make lines function
require(ggplot2)
require(gpclib)

## in any case, using ggplot2 capabilities
county$labpt = coordinates(county)

county$labpt gives me the centroid of all my polygons and I think these follow the order 1:3258 

> county$labpt[1:1,1:2] 
[1] -71.57849  41.17788
> county$fips[1]
[1] "44009"

so county$fips[1] "44009" should have its centroid at [1] -71.57849  41.17788

I'm trying to figure out how I am going to make lines between say county$in_start[6] as startpoint

> county$in_start <- !is.na(county$m_0910_in_orig)
> county$in_start
   [1] FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE

and county$in_end[6] as endpoint

> county$in_end <- !is.na(county$m_0910_in_dest)
> county$in_end
   [1] FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE

I feel like I have most of the pieces but have lost track somewhere.  Any suggestions
greatly appreciated.

Thanks,
Chris  



 		 	   		  
	[[alternative HTML version deleted]]

