Plotting shapefiles in R

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Plotting shapefiles in R

Ester Polaina Lacambra
Hello,

I am trying to perform several spatial analysis on R, based on polygon
lists. My data come from ArcGIS, being in shape format. I would like to
create a polygon list from this file. Apparently, R reads properly the file
by using the function "read.shapefile", however when I try the function
"plot" on this object, the program does not recognize which are the X and Y
coordinates (which -by the way- are in decimal degree units). Should I use
any specific sintaxis to indicate which columns are my coordinates? or
maybe I have to project my coordinates somehow?

Thank you very much indeed,

--
Ester

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Plotting shapefiles in R

celso
Try this:

## read polygon SHP
library(shapefiles)
poli<-read.shapefile("your shp file name")
poli<-convert.to.simple(poli$shp)
poli<-poli[,-1]
plot(poli)





> Hello,
>
> I am trying to perform several spatial analysis on R, based on polygon
> lists. My data come from ArcGIS, being in shape format. I would like to
> create a polygon list from this file. Apparently, R reads properly the
> file
> by using the function "read.shapefile", however when I try the function
> "plot" on this object, the program does not recognize which are the X and
> Y
> coordinates (which -by the way- are in decimal degree units). Should I use
> any specific sintaxis to indicate which columns are my coordinates? or
> maybe I have to project my coordinates somehow?
>
> Thank you very much indeed,
>
> --
> Ester
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Plotting shapefiles in R

Roger Bivand
Administrator
On Wed, 11 Jan 2012, [hidden email] wrote:

> Try this:

Please note that the shapefiles package has not been revised since 2006,
and does not use sp classes, so you are completely stuck with the import
data representation of that package. See the "Spatial" task view on CRAN
for better supported alternatives.

Roger

>
> ## read polygon SHP
> library(shapefiles)
> poli<-read.shapefile("your shp file name")
> poli<-convert.to.simple(poli$shp)
> poli<-poli[,-1]
> plot(poli)
>
>
>
>
>
>> Hello,
>>
>> I am trying to perform several spatial analysis on R, based on polygon
>> lists. My data come from ArcGIS, being in shape format. I would like to
>> create a polygon list from this file. Apparently, R reads properly the
>> file
>> by using the function "read.shapefile", however when I try the function
>> "plot" on this object, the program does not recognize which are the X and
>> Y
>> coordinates (which -by the way- are in decimal degree units). Should I use
>> any specific sintaxis to indicate which columns are my coordinates? or
>> maybe I have to project my coordinates somehow?
>>
>> Thank you very much indeed,
>>
>> --
>> Ester
>>
>> [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

--
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: [hidden email]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

Re: Plotting shapefiles in R

Tom Philippi
Roger didn't say it (but he wrote the book on it), but an alternative
would be something like:
library(sp)
library(rgdall)
poli<-readOGR("directory","shapefilename without .shp")
class(poli) # SpatialPolygonsDataFrame
proj4string(poli) # projection information
spplot(poli)

One advantage is that by using sp classes, this approach allows you to
reproject via spTransform(), colorize polygons by values of an
attribute in the dataframe in spplot(), and actually do more things
with the spatial data.

Tom 2

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Plotting shapefiles in R

Thiago V. dos Santos
In reply to this post by Ester Polaina Lacambra
  Dear Ester,

  This is a simple, yet effective, approach:
 
  library(maptools)
  myshp<-readShapePoly("path_to_your_shapefile")
  plot(myshp)

  Hope it helps,

  Thiago.

--- On Wed, 11/1/12, Ester Polaina Lacambra <[hidden email]> wrote:

> From: Ester Polaina Lacambra <[hidden email]>
> Subject: [R-sig-Geo] Plotting shapefiles in R
> To: [hidden email]
> Date: Wednesday, 11 January, 2012, 7:20
> Hello,
>
> I am trying to perform several spatial analysis on R, based
> on polygon
> lists. My data come from ArcGIS, being in shape format. I
> would like to
> create a polygon list from this file. Apparently, R reads
> properly the file
> by using the function "read.shapefile", however when I try
> the function
> "plot" on this object, the program does not recognize which
> are the X and Y
> coordinates (which -by the way- are in decimal degree
> units). Should I use
> any specific sintaxis to indicate which columns are my
> coordinates? or
> maybe I have to project my coordinates somehow?
>
> Thank you very much indeed,
>
> --
> Ester
>
>     [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo