[R-sig-Geo] mapping by zip codes

Torleif Markussen Lunde torleif.lunde at cih.uib.no
Thu Mar 5 20:26:33 CET 2009


Dear Alina

First of all I suggest you search this mailing list, google, as well as 
reading a little at http://r-spatial.sourceforge.net/ 
Especially the Graph gallery is useful with lots of examples. If you want to 
advance, please look at http://www.asdar-book.org/


The answer to your question is 
require(sp)
xyz.df <- data.frame(x=c(50,60,70), y=c(60,40, 80), customers=c(1654, 986, 
2678))
coordinates(xyz.df) <- ~x+y
proj4string(xyz.df) <- CRS("+proj=longlat +datum=WGS84") #Use right projection
class(xyz.df)
str(xyz.df)

Best wishes
Torleif

On Thursday 05 March 2009 07:58:47 pm Alina Sheyman wrote:
> My data consists of lat, long, and the number of customers associated with
> each
> How do I go about converting my data.frame to a spatial object?
>
> On Tue, Mar 3, 2009 at 3:40 PM, Paul Hiemstra <p.hiemstra at geo.uu.nl> wrote:
> > Hi,
> >
> > You have to provide some more info in order for us to answer you
> > question. How does 'your data' look like? A data.frame with x and y
> > coordinates and more info? If this is correct, you need to convert the xy
> > data.frame to a spatial object:
> >
> > library(sp)
> > data(meuse) # data.frame
> > # The columns with the x and y coordinates are called "x" and "y"
> > coordinates(meuse) = ~x+y # SpatialPointsDataFrame
> >
> > Then you can use overlay() to find out in which customer is in which
> > polygon. Then you can count the number of customers per zip code.
> >
> > cheers,
> > Paul
> >
> > Alina Sheyman schreef:
> >> I'm very new to creating maps using shapefiles, so this question might
> >> be pretty basic.
> >>
> >> I'm trying to create a map of the US, divided up by zip codes, where i
> >> then
> >> map number of customers by zip code.
> >> I located shapefiles for US with zip codes (although at this point only
> >> for
> >> individual states, and not the entire country) and read it into R using
> >> maptools,
> >> but now I need to apply my data (which I read into R as a separate data
> >> frame and not a shapefile) to that map. Which is the part where I get
> >> completely lost and not sure how to proceed. If anyone could give me any
> >> pointers I'd really appreciate it.
> >>
> >> thank you
> >>
> >>        [[alternative HTML version deleted]]
> >>
> >> _______________________________________________
> >> R-sig-Geo mailing list
> >> R-sig-Geo at stat.math.ethz.ch
> >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
> > --
> > Drs. Paul Hiemstra
> > Department of Physical Geography
> > Faculty of Geosciences
> > University of Utrecht
> > Heidelberglaan 2
> > P.O. Box 80.115
> > 3508 TC Utrecht
> > Phone:  +3130 274 3113 Mon-Tue
> > Phone:  +3130 253 5773 Wed-Fri
> > http://intamap.geo.uu.nl/~paul <http://intamap.geo.uu.nl/%7Epaul>
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list