[R-sig-Geo] Graphing Canadian Cities via Forward Station Area (FSAs) Spatial Information

Mike Sukmanowsky mike.sukmanowsky at gmail.com
Mon Apr 9 22:42:32 CEST 2012


Thanks so much Michael!

That worked perfectly and I'm definitely going to check out the book
that you mentioned below.

An R question for you though, I did something similar to what you
recommended but didn't yield the same result:

# Create a gta.spatial dataframe which only contains L and M FSAs.
gta.fsas                <- grep("[LM][0-9][A-Z]",
as.character(canada.fsa.spatial at data$CENSUS_FSA))
gta.spatial <- canada.fsa.spatial at data[gta.fsas,]


When I plotted my gta.spatial above it still showed all of canada.
Why does subset seem to properly remove the elements from the data
frame whereas my attempt to construct a new data frame didn't work?

Thank you once again.

On Mon, Apr 9, 2012 at 3:17 PM, Michael Friendly <friendly at yorku.ca> wrote:
> Look at ?subset.Spatial
>
> Perhaps this will get you started, but you should probably buy & read
> Applied Spatial Data Analysis with R by Bivand etal/
>
> # examine  first letter of postal code for GTA
> table(substr(canada.fsa.spatial$CENSUS_FSA,1,1))
>
>
> inLM <- substr(canada.fsa.spatial$CENSUS_FSA,1,1) %in% c('L','M')
> GTA <- subset(canada.fsa.spatial, inLM)
>
> plot(GTA)
>
>
>
>
>
> On 4/5/2012 4:33 PM, Mike Sukmanowsky wrote:
>>
>> Hi everyone,
>>
>> We're trying to overlay some internal information that we have regarding
>> certain Canadian cities.  The data that we have is specified by Forward
>> Station Area (FSA) which corresponds to the first three digits of a
>> Canadian postal code.
>>
>> The Government of Canada provides a shapefile (.dbf, .shp, .prj, .shx)
>> from
>> the 2006 Census for all FSAs in Canada.
>>
>> The current question I have is how to use this shapefile to effectively
>> "zoom in" to just a few Canadian cities / areas and then display a
>> choropleth just of a certain area (the Greater Toronto Area for example
>> which is roughly equivalent to all FSAs which start with the letter L or
>> M).
>>
>> Here's the code I'm currently using as well as a link to the shapefile
>> itself.  Can someone provide an example of how to "zoom in" to Toronto for
>> example and display a choropleth with some randomized data as an example?
>>  I'm just not positive how to use the maps, maptools, sp, etc libraries to
>> limit the plot to a specific area and then add additional data to the data
>> frame for the purpose of the choropleth.
>>
>> library(maps)
>> library(maptools)
>> library(sp)
>>
>> # Zip file available from
>> https://s3.amazonaws.com/tgam.general/gfsa000a06a_e.zip
>> # PDF explaining file available here
>> https://s3.amazonaws.com/tgam.general/92-170-GIE2006001.pdf
>> canada.fsa.spatial<-
>> readShapePoly("~/Documents/Census/2006/gfsa000a06a_e/gfsa000a06a_e",
>> IDvar="CENSUS_FSA",
>> verbose=T)
>
>
>
> --
> Michael Friendly     Email: friendly AT yorku DOT ca
> Professor, Psychology Dept.
> York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
> 4700 Keele Street    Web:   http://www.datavis.ca
> Toronto, ONT  M3J 1P3 CANADA
>



-- 
Mike Sukmanowsky



More information about the R-sig-Geo mailing list