Re: [R] Coloring Canada provinces (package maps?)

2012-01-26 Thread Dimitri Liakhovitski
Barry, thanks a lot!
I was able to read in Candian data set from gadm:

library(raster)
# Finding ISO3 code for Canada
getData('ISO3')  # Canada's code is CAN
# Reading in data at different levels
can0-getData('GADM', country=CAN, level=0)
can1-getData('GADM', country=CAN, level=1)
can2-getData('GADM', country=CAN, level=2)
class(can0)
str(can0)
class(can1)
str(can1)

Apologies for a novice question (I've never worked with maps and
raster before): what is the way in raster to see what are the
geographic units within each data set (can0, can1, can2)?
And what function allows to plot them and color them?

Thanks a lot for the hints!
Dimitri



On Wed, Jan 25, 2012 at 4:37 PM, Barry Rowlingson
b.rowling...@lancaster.ac.uk wrote:
 On Wed, Jan 25, 2012 at 9:25 PM, Dimitri Liakhovitski
 dimitri.liakhovit...@gmail.com wrote:
 Dear R'ers,

 I am wondering what is the smallest geographicterritorial unit
 available for formatting in Canada. Provinces?


 I know that in the US it is the county so that I can color US
 counties any way I want, for example:

 ### Example for coloring US counties
 ### Creating an ARTIFICIAL criterion for coloring US counties:
 library(maps)

 If you want to extend your skills beyond the map package then you can
 plot anything that you can get a shapefile, or other common geospatial
 data set of, using the sp packages and friends such as maptools and
 rgdal.

  gadm has four levels of Canadian boundaries, at first glance -
 country, province (black), something smaller than province (blue) and
 then red which looks like urban divisions.

  The province upper-left doesn't seem to have any blue subdivisions,
 but that's possibly because there would be more subdivisions than
 people who actually live there.

 http://www.gadm.org/download

  Gadm also has a facility to download the data as .Rdata objects that
 can load straight into R.

  You might want to ask questions about spatial data programming on
 R-sig-geo or even on www.stackoverflow.com with the R tag.

 Barry



-- 
Dimitri Liakhovitski
marketfusionanalytics.com

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Coloring Canada provinces (package maps?)

2012-01-26 Thread Barry Rowlingson
On Thu, Jan 26, 2012 at 4:03 PM, Dimitri Liakhovitski
dimitri.liakhovit...@gmail.com wrote:
 Barry, thanks a lot!
 I was able to read in Candian data set from gadm:

 library(raster)
 # Finding ISO3 code for Canada
 getData('ISO3')  # Canada's code is CAN
 # Reading in data at different levels
 can0-getData('GADM', country=CAN, level=0)
 can1-getData('GADM', country=CAN, level=1)
 can2-getData('GADM', country=CAN, level=2)
 class(can0)
 str(can0)
 class(can1)
 str(can1)

 Apologies for a novice question (I've never worked with maps and
 raster before): what is the way in raster to see what are the
 geographic units within each data set (can0, can1, can2)?
 And what function allows to plot them and color them?

 These are now SpatialPolygonDataFrame objects - like data frames, but
each row has an associated polygonal geometry. These actually come
from the sp package which the raster package has loaded for you.

 class(can0) will tell you this.

 names(can1) will tell you the names of the attributes of the polygons
which you can use like columns of a data frame.

 plot(can1) will plot it

 spplot(can1, columnname) will do a coloured plot.

 For more info, check the help for sp or read the R-Spatial Task View
on CRAN which has everything you need to know about maps and such in
R.

 Ask any more questions like this on the R-sig-geo mailing list where
the mapping R people hang out...

Barry

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Coloring Canada provinces (package maps?)

2012-01-26 Thread Dimitri Liakhovitski
Thank you very much, Barry!
Dimitri

On Thu, Jan 26, 2012 at 12:00 PM, Barry Rowlingson
b.rowling...@lancaster.ac.uk wrote:
 On Thu, Jan 26, 2012 at 4:03 PM, Dimitri Liakhovitski
 dimitri.liakhovit...@gmail.com wrote:
 Barry, thanks a lot!
 I was able to read in Candian data set from gadm:

 library(raster)
 # Finding ISO3 code for Canada
 getData('ISO3')  # Canada's code is CAN
 # Reading in data at different levels
 can0-getData('GADM', country=CAN, level=0)
 can1-getData('GADM', country=CAN, level=1)
 can2-getData('GADM', country=CAN, level=2)
 class(can0)
 str(can0)
 class(can1)
 str(can1)

 Apologies for a novice question (I've never worked with maps and
 raster before): what is the way in raster to see what are the
 geographic units within each data set (can0, can1, can2)?
 And what function allows to plot them and color them?

  These are now SpatialPolygonDataFrame objects - like data frames, but
 each row has an associated polygonal geometry. These actually come
 from the sp package which the raster package has loaded for you.

  class(can0) will tell you this.

  names(can1) will tell you the names of the attributes of the polygons
 which you can use like columns of a data frame.

  plot(can1) will plot it

  spplot(can1, columnname) will do a coloured plot.

  For more info, check the help for sp or read the R-Spatial Task View
 on CRAN which has everything you need to know about maps and such in
 R.

  Ask any more questions like this on the R-sig-geo mailing list where
 the mapping R people hang out...

 Barry



-- 
Dimitri Liakhovitski
marketfusionanalytics.com

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Coloring Canada provinces (package maps?)

2012-01-25 Thread Dimitri Liakhovitski
Dear R'ers,

I am wondering what is the smallest geographicterritorial unit
available for formatting in Canada. Provinces?


I know that in the US it is the county so that I can color US
counties any way I want, for example:

### Example for coloring US counties
### Creating an ARTIFICIAL criterion for coloring US counties:
library(maps)
allcounties-data.frame(county=map('county', plot=FALSE)$names)
allcounties$group-c(rep(1:6,513),rep(1,4))[order(c(rep(1:6,513),rep(1,4)))]
### My colors:
mycolors - rainbow(6)
map('county',fill=TRUE,col=mycolors[allcounties$group],resolution=0,lty=0,bg
= transparent)
map('state', lwd=1, add=TRUE)

I would like to do something similar for Canada. I see that maps knows
Canadian cities:

map(world, Canada)
map.cities(country = Canada,Capitals = 2)

But how could I access and map Canada's provinces?
Or maybe there are some even smaller territorial units in Canada (like
counties in the US)? If yes, then in what package are they accessible?

Thanks a lot!

-- 
Dimitri Liakhovitski
marketfusionanalytics.com

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Coloring Canada provinces (package maps?)

2012-01-25 Thread Barry Rowlingson
On Wed, Jan 25, 2012 at 9:25 PM, Dimitri Liakhovitski
dimitri.liakhovit...@gmail.com wrote:
 Dear R'ers,

 I am wondering what is the smallest geographicterritorial unit
 available for formatting in Canada. Provinces?


 I know that in the US it is the county so that I can color US
 counties any way I want, for example:

 ### Example for coloring US counties
 ### Creating an ARTIFICIAL criterion for coloring US counties:
 library(maps)

If you want to extend your skills beyond the map package then you can
plot anything that you can get a shapefile, or other common geospatial
data set of, using the sp packages and friends such as maptools and
rgdal.

 gadm has four levels of Canadian boundaries, at first glance -
country, province (black), something smaller than province (blue) and
then red which looks like urban divisions.

 The province upper-left doesn't seem to have any blue subdivisions,
but that's possibly because there would be more subdivisions than
people who actually live there.

http://www.gadm.org/download

 Gadm also has a facility to download the data as .Rdata objects that
can load straight into R.

 You might want to ask questions about spatial data programming on
R-sig-geo or even on www.stackoverflow.com with the R tag.

Barry

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.