An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110403/9d91acb5/attachment.pl>
another question on shapefiles and geom_point in ggplot2
6 messages · Manuel Spínola, Felipe Carrillo, Pierre Roudier +1 more
Thank you very much Felipe,
Did you see the solution from ahmadou dicko?
He doesn?t use gpclibPermit()
I have another option but I cannot get the right fill for the id.
See attached map.
ai_biotica = readOGR(dsn="C:/ProyectosRespacial/ICE/SIG_Biotica_PHED",
layer="AI_BIOTICA_010411_CRTM05")
str(ai_biotica)
# fortify to get the data
fortify.ai_biotica <-
fortify.SpatialPolygonsDataFrame(ai_biotica,region='Area_Influ')
names(fortify.ai_biotica)
str(fortify.ai_biotica)
levels(fortify.ai_biotica$group)
# mapa
ggplot(fortify.ai_biotica, aes(x = long, y=lat, group = group)) +
geom_polygon(colour = "black", fill = NA)
geo = read.csv("riqueza_out.csv", sep = ",", header = T)
names(geo)
str(geo)
summary(geo)
# mapa con riqueza
p = ggplot(geo, aes(x, y))
p + geom_point(aes(size = ACE, colour = ACE)) + theme_bw() +
scale_size(name = "N?mero de especies", breaks = c(2, 4, 6, 8, 10, 12,
14, 16, 18, 20)) + scale_colour_gradientn(name = 'N?mero de especies',
colours = heat.colors(10), breaks = c(2, 4, 6, 8, 10, 12, 14, 16, 18,
20))+ xlab("Longitud") + ylab("Latitud") + opts(axis.text.x =
theme_text(size = 8, vjust = 1)) + opts(axis.text.y = theme_text(size =
8, hjust = 1)) + geom_path(aes(x=long,y=lat,group=group,
fill=id),data=fortify.ai_biotica)
Best,
Manuel
On 03/04/2011 01:41 p.m., Felipe Carrillo wrote:
Manuel:
I changed your variable names from x to 'long' and y to 'lat' on the
riqueza_out.csv file.
The code below should do what you want. Also, since the legend title
is kind of long, I broke it
down into three lines so you can see more plot area. I am cc'ing the
other groups so more people
use it if needed.
library(rgdal)
library(ggplot2)
library(sp)
library(maptools)
gpclibPermit()
manuel <- readOGR(dsn=".", layer="AI_BIOTICA_010411_CRTM05")
names(manuel);dim(manuel)
slotNames(manuel) # look at the slot names
# add the 'id' variable to the shapefile and use it to merge both files
manuel at data$id <mailto:manuel at data$id> = rownames(manuel at data
<mailto:manuel at data>)
# convert shapefile to dataframe
manuel.df <- as.data.frame(manuel)
# fortify to plot with ggplot2
manuel_fort <- fortify(manuel,region="id")
head(manuel_fort)
# Merge shapefile and the as.dataframe shapefile
manuel_merged <- join(manuel_fort,manuel.df, by ="id")
head(manuel_merged)
# Read in the csv file
manuel_points <- read.csv("riqueza_out.csv")
head(manuel_points);dim(manuel_points)
# fortify this one too for the points or else an error will ocurr
manuel_points <- fortify(manuel_points)
manuel_points
# Plot the shapefile and overlayed the points over it
p <- ggplot(manuel_merged, aes(long,lat,group=group)) +
geom_polygon(aes(data=manuel_merged,fill=Area_Influ)) +
geom_path(color="white") + theme_bw() # remove this if you don't
want black and white background
p + geom_point(data=manuel_points,aes(size=ACE,colour=ACE,group=NULL)) +
scale_size(name = "N?mero\nde\nespecies", breaks = c(2, 4, 6, 8, 10,
12, 14, 16, 18, 20)) +
scale_colour_gradientn(name = 'N?mero\nde\nespecies',
colours = rainbow(6), breaks = c(2, 4, 6, 8, 10, 12, 14, 16, 18, 20))+
xlab("Longitud") + ylab("Latitud") + opts(axis.text.x =
theme_text(size = 8, vjust = 1)) +
opts(axis.text.y = theme_text(size = 8, hjust = 1))
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx
*From:* Manuel Sp?nola <mspinola10 at gmail.com>
*To:* Felipe Carrillo <mazatlanmexico at yahoo.com>
*Sent:* Sat, April 2, 2011 11:22:24 PM
*Subject:* Re: another question on shapefiles and geom_point in
ggplot2
No problem, thank you very much Felipe.
Best,
Manuel
On 03/04/2011 12:19 a.m., Felipe Carrillo wrote:
I meant to send you this one..Let me clean up the code a little
bit and
I will send it to you,,,do you mind if I send it to you in the
morning?
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx
*From:* Manuel Sp?nola <mspinola10 at gmail.com>
*To:* Felipe Carrillo <mazatlanmexico at yahoo.com>
*Sent:* Sat, April 2, 2011 11:15:28 PM
*Subject:* Re: another question on shapefiles and geom_point
in ggplot2
Yes Felipe. That is the graph I was looking for.
I got something closer but no like yours. How did you do it?
Manuel
On 03/04/2011 12:10 a.m., Felipe Carrillo wrote:
I was able to open them,,I am attaching a picture of the
graph I created..It's that what
you had in mind?
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx
*From:* Manuel Sp?nola <mspinola10 at gmail.com>
*To:* Felipe Carrillo <mazatlanmexico at yahoo.com>
*Sent:* Sat, April 2, 2011 10:35:51 PM
*Subject:* Re: another question on shapefiles and
geom_point in ggplot2
It should be. I am sending them again.
Manuel
On 02/04/2011 10:23 p.m., Felipe Carrillo wrote:
Manuel:
I can't open the shapefile, is this the original one?
Is the csv file the one that you are trying to overlay
on top of the shapefile?
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx
*From:* Manuel Sp?nola <mspinola10 at gmail.com>
*To:* Felipe Carrillo <mazatlanmexico at yahoo.com>
*Sent:* Sat, April 2, 2011 6:14:09 PM
*Subject:* Re: another question on shapefiles and
geom_point in ggplot2
Files attached.
On 02/04/2011 07:04 p.m., Felipe Carrillo wrote:
If you want individual points overlayed on the
shapefile, you need to add another variable to it
before you fortify it.
After you fortify merge both the fortified dataset
and the original shapefile. Go ahead and post your
shapefile to see if
I can figure it out. Do you just want the points
or want text also?
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx
*From:* Manuel Sp?nola <mspinola10 at gmail.com>
*To:* Felipe Carrillo <mazatlanmexico at yahoo.com>
*Sent:* Sat, April 2, 2011 5:24:02 PM
*Subject:* Re: another question on shapefiles
and geom_point in ggplot2
Hi Felipe,
I did the same thing that I am trying know,
attached is how it looks.
Best,
Manuel
On 02/04/2011 06:09 p.m., Felipe Carrillo wrote:
Manuel:
I did something similar a few weeks ago,,If
you post your shapefile and describe what you are
expecting I might be able to help..
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx
*From:* Manuel Sp?nola <mspinola10 at gmail.com>
*To:* "ggplot2 at googlegroups.com"
<ggplot2 at googlegroups.com>
*Sent:* Sat, April 2, 2011 12:01:56 PM
*Subject:* another question on shapefiles
and geom_point in ggplot2
Dear list members,
This is a different question from my
previous post.
I handle to read my shapefile with
ggplot2 following
https://github.com/hadley/ggplot2/wiki/plotting-polygon-shapefiles
p = ggplot(ai_biotica.df,
aes(long,lat,group=group,fill=Area_Influ)) +
geom_polygon() +
geom_path(color="white") +
coord_equal()
I got a nice map.
Now I want to plot some point with
geom_point but I got an error.
> p + geom_point(geo, aes(size = ACE,
colour = ACE)) + scale_size(name =
"N?mero de especies", breaks = c(2, 4, 6,
8, 10, 12, 14, 16, 18, 20)) +
scale_colour_gradientn(name = 'N?mero de
especies', colours = rainbow(6), breaks =
c(2, 4, 6, 8, 10, 12, 14, 16, 18, 20))+
xlab("Longitud") + ylab("Latitud") +
opts(axis.text.x = theme_text(size = 8,
vjust = 1)) + opts(axis.text.y =
theme_text(size = 8, hjust = 1))
Error: ggplot2 doesn't know how to deal
with data of class uneval
Best,
Manuel
--
*Manuel Sp?nola, Ph.D.*
Instituto Internacional en Conservaci?n y
Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspinola at una.ac.cr
mspinola10 at gmail.com
Tel?fono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de r?o
<https://sites.google.com/site/lobitoderio/>
Institutional website: ICOMVIS
<http://www.icomvis.una.ac.cr/>
--
You received this message because you are
subscribed to the ggplot2 mailing list.
Please provide a reproducible example:
http://gist.github.com/270442
To post: email ggplot2 at googlegroups.com
To unsubscribe: email
ggplot2+unsubscribe at googlegroups.com
More options:
http://groups.google.com/group/ggplot2
--
*Manuel Sp?nola, Ph.D.*
Instituto Internacional en Conservaci?n y
Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspinola at una.ac.cr
mspinola10 at gmail.com
Tel?fono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de r?o
<https://sites.google.com/site/lobitoderio/>
Institutional website: ICOMVIS
<http://www.icomvis.una.ac.cr/>
--
*Manuel Sp?nola, Ph.D.*
Instituto Internacional en Conservaci?n y Manejo de
Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspinola at una.ac.cr
mspinola10 at gmail.com
Tel?fono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de r?o
<https://sites.google.com/site/lobitoderio/>
Institutional website: ICOMVIS
<http://www.icomvis.una.ac.cr/>
--
*Manuel Sp?nola, Ph.D.*
Instituto Internacional en Conservaci?n y Manejo de Vida
Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspinola at una.ac.cr
mspinola10 at gmail.com
Tel?fono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de r?o
<https://sites.google.com/site/lobitoderio/>
Institutional website: ICOMVIS
<http://www.icomvis.una.ac.cr/>
--
*Manuel Sp?nola, Ph.D.*
Instituto Internacional en Conservaci?n y Manejo de Vida
Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspinola at una.ac.cr
mspinola10 at gmail.com
Tel?fono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de r?o
<https://sites.google.com/site/lobitoderio/>
Institutional website: ICOMVIS <http://www.icomvis.una.ac.cr/>
--
*Manuel Sp?nola, Ph.D.*
Instituto Internacional en Conservaci?n y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspinola at una.ac.cr
mspinola10 at gmail.com
Tel?fono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de r?o
<https://sites.google.com/site/lobitoderio/>
Institutional website: ICOMVIS <http://www.icomvis.una.ac.cr/>
*Manuel Sp?nola, Ph.D.* Instituto Internacional en Conservaci?n y Manejo de Vida Silvestre Universidad Nacional Apartado 1350-3000 Heredia COSTA RICA mspinola at una.ac.cr mspinola10 at gmail.com Tel?fono: (506) 2277-3598 Fax: (506) 2237-7036 Personal website: Lobito de r?o <https://sites.google.com/site/lobitoderio/> Institutional website: ICOMVIS <http://www.icomvis.una.ac.cr/> -------------- next part -------------- A non-text attachment was scrubbed... Name: riqueza.png Type: image/png Size: 14825 bytes Desc: riqueza.png URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110403/105d1def/attachment.png>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110403/faeaedc9/attachment.pl>
Hi all, 2011/4/4 Felipe Carrillo <mazatlanmexico at yahoo.com>:
Manuel: As?far as I know?one needs gpclibPermit() in order to fortify see this: Note: polygon geometry computations in maptools ??????? depend on the package gpclib, which has a ??????? restricted licence. It is disabled by default; ??????? to enable gpclib, type gpclibPermit() I am going to guess that ahmadou dicko doesn't show gpclibPermit() on his code because he loaded it with Rprofile or some other way. I tried to run his code without gpclibPermit() and it wouldn't let me fortify, so not sure how he did it.
On that specific point, Colin Arundel and Roger Bivant released the rgeos package on CRAN a few days [1]. This is a great achievement as it brings bindings to the GEOS C++ lib [2] - long story short, it makes the job the non-free [3] gpclib used to do. In its later release, maptools has an option to check if rgeos if present - if it is the case it is used instead of gpclib:
library(maptools)
Loading required package: foreign
Loading required package: sp
Loading required package: lattice
Note: polygon geometry computations in maptools
depend on the package gpclib, which has a
restricted licence. It is disabled by default;
to enable gpclib, type gpclibPermit()
Checking rgeos availability as gpclib substitute:
TRUE
?gpclibPermit
Pierre [1] http://cran.r-project.org/web/packages/rgeos/ [2] http://trac.osgeo.org/geos/ [3] https://stat.ethz.ch/pipermail/r-sig-geo/2010-January/007400.html
Scientist Landcare Research, New Zealand
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110404/92d1e250/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110404/925d6c3d/attachment.pl>