Re: another question on shapefiles and geom_point in ggplot2

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: another question on shapefiles and geom_point in ggplot2

Felipe Carrillo
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@data$id = rownames(manuel@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 <[hidden email]>
>To: Felipe Carrillo <[hidden email]>
>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 <[hidden email]>
>>>To: Felipe Carrillo <[hidden email]>
>>>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 <[hidden email]>
>>>>>To: Felipe Carrillo <[hidden email]>
>>>>>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 <[hidden email]>
>>>>>>>To: Felipe Carrillo <[hidden email]>
>>>>>>>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 <[hidden email]>
>>>>>>>>>To: Felipe Carrillo <[hidden email]>
>>>>>>>>>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 <[hidden email]>
>>>>>>>>>>>To: "[hidden email]" <[hidden email]>
>>>>>>>>>>>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
>>>>>>>>>>>[hidden email]
>>>>>>>>>>>[hidden email]
>>>>>>>>>>>Teléfono: (506) 2277-3598
>>>>>>>>>>>Fax: (506) 2237-7036
>>>>>>>>>>>Personal website: Lobito de río
>>>>>>>>>>>Institutional website: ICOMVIS --
>>>>>>>>>>>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 [hidden email]
>>>>>>>>>>>To unsubscribe: email [hidden email]
>>>>>>>>>>>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
>>>>>>>>[hidden email]
>>>>>>>>[hidden email]
>>>>>>>>Teléfono: (506) 2277-3598
>>>>>>>>Fax: (506) 2237-7036
>>>>>>>>Personal website: Lobito de río
>>>>>>>>Institutional website: ICOMVIS
>>>>>>
>>>>>>
>>>>>>--
>>>>>>Manuel Spínola, Ph.D.
>>>>>>Instituto Internacional en Conservación y Manejo de Vida Silvestre
>>>>>>Universidad Nacional
>>>>>>Apartado 1350-3000
>>>>>>Heredia
>>>>>>COSTA RICA
>>>>>>[hidden email]
>>>>>>[hidden email]
>>>>>>Teléfono: (506) 2277-3598
>>>>>>Fax: (506) 2237-7036
>>>>>>Personal website: Lobito de río
>>>>>>Institutional website: ICOMVIS
>>>>
>>>>
>>>>--
>>>>Manuel Spínola, Ph.D.
>>>>Instituto Internacional en Conservación y Manejo de Vida Silvestre
>>>>Universidad Nacional
>>>>Apartado 1350-3000
>>>>Heredia
>>>>COSTA RICA
>>>>[hidden email]
>>>>[hidden email]
>>>>Teléfono: (506) 2277-3598
>>>>Fax: (506) 2237-7036
>>>>Personal website: Lobito de río
>>>>Institutional website: ICOMVIS
>>
>>
>>--
>>Manuel Spínola, Ph.D.
>>Instituto Internacional en Conservación y Manejo de Vida Silvestre
>>Universidad Nacional
>>Apartado 1350-3000
>>Heredia
>>COSTA RICA
>>[hidden email]
>>[hidden email]
>>Teléfono: (506) 2277-3598
>>Fax: (506) 2237-7036
>>Personal website: Lobito de río
>>Institutional website: ICOMVIS

--
Manuel Spínola, Ph.D.
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
[hidden email]
[hidden email]
Teléfono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de río
Institutional website: ICOMVIS
        [[alternative HTML version deleted]]


______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: another question on shapefiles and geom_point in ggplot2

Manuel Spínola-2
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@data$id <mailto:manuel@data$id> = rownames(manuel@data
> <mailto:manuel@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 <[hidden email]>
>     *To:* Felipe Carrillo <[hidden email]>
>     *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 <[hidden email]>
>>         *To:* Felipe Carrillo <[hidden email]>
>>         *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 <[hidden email]>
>>>             *To:* Felipe Carrillo <[hidden email]>
>>>             *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 <[hidden email]>
>>>>                 *To:* Felipe Carrillo <[hidden email]>
>>>>                 *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 <[hidden email]>
>>>>>                     *To:* Felipe Carrillo <[hidden email]>
>>>>>                     *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 <[hidden email]>
>>>>>>                         *To:* "[hidden email]"
>>>>>>                         <[hidden email]>
>>>>>>                         *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
>>>>>>                         [hidden email]
>>>>>>                         [hidden email]
>>>>>>                         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 [hidden email]
>>>>>>                         To unsubscribe: email
>>>>>>                         [hidden email]
>>>>>>                         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
>>>>>                     [hidden email]
>>>>>                     [hidden email]
>>>>>                     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
>>>>                 [hidden email]
>>>>                 [hidden email]
>>>>                 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
>>>             [hidden email]
>>>             [hidden email]
>>>             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
>>         [hidden email]
>>         [hidden email]
>>         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
>     [hidden email]
>     [hidden email]
>     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
[hidden email]
[hidden email]
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/>

______________________________________________
[hidden email] 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.

riqueza.png (19K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: another question on shapefiles and geom_point in ggplot2

Felipe Carrillo
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 the same note, your code didn't work when you were trying to join ai_biotica
and ai_biotica@data
because you are trying to join polygons and points (just a guess). Try to use
fortify instead of fortify.SpatialPolygonsDataFrame. I tested with a different
shapefile and it works for me.

manuel@data$id = rownames(manuel@data)
   manuel_fort <- fortify(manuel,region="id")
  manuel_merged <- join(manuel_fort,manuel@data, by ="id")

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 <[hidden email]>
>To: Felipe Carrillo <[hidden email]>
>Cc: [hidden email]; [hidden email]
>Sent: Sun, April 3, 2011 1:51:02 PM
>Subject: Re: another question on shapefiles and geom_point in ggplot2
>
>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@data$id = rownames(manuel@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 <[hidden email]>
>>>To: Felipe Carrillo <[hidden email]>
>>>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 <[hidden email]>
>>>>>To: Felipe Carrillo <[hidden email]>
>>>>>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 <[hidden email]>
>>>>>>>To: Felipe Carrillo <[hidden email]>
>>>>>>>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 <[hidden email]>
>>>>>>>>>To: Felipe Carrillo <[hidden email]>
>>>>>>>>>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 <[hidden email]>
>>>>>>>>>>>To: Felipe Carrillo <[hidden email]>
>>>>>>>>>>>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 <[hidden email]>
>>>>>>>>>>>>>To: "[hidden email]" <[hidden email]>
>>>>>>>>>>>>>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
>>>>>>>>>>>>>[hidden email]
>>>>>>>>>>>>>[hidden email]
>>>>>>>>>>>>>Teléfono: (506) 2277-3598
>>>>>>>>>>>>>Fax: (506) 2237-7036
>>>>>>>>>>>>>Personal website: Lobito de río
>>>>>>>>>>>>>Institutional website: ICOMVIS --
>>>>>>>>>>>>>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 [hidden email]
>>>>>>>>>>>>>To unsubscribe: email [hidden email]
>>>>>>>>>>>>>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
>>>>>>>>>>[hidden email]
>>>>>>>>>>[hidden email]
>>>>>>>>>>Teléfono: (506) 2277-3598
>>>>>>>>>>Fax: (506) 2237-7036
>>>>>>>>>>Personal website: Lobito de río
>>>>>>>>>>Institutional website: ICOMVIS
>>>>>>>>
>>>>>>>>
>>>>>>>>--
>>>>>>>>Manuel Spínola, Ph.D.
>>>>>>>>Instituto Internacional en Conservación y Manejo de Vida Silvestre
>>>>>>>>Universidad Nacional
>>>>>>>>Apartado 1350-3000
>>>>>>>>Heredia
>>>>>>>>COSTA RICA
>>>>>>>>[hidden email]
>>>>>>>>[hidden email]
>>>>>>>>Teléfono: (506) 2277-3598
>>>>>>>>Fax: (506) 2237-7036
>>>>>>>>Personal website: Lobito de río
>>>>>>>>Institutional website: ICOMVIS
>>>>>>
>>>>>>
>>>>>>--
>>>>>>Manuel Spínola, Ph.D.
>>>>>>Instituto Internacional en Conservación y Manejo de Vida Silvestre
>>>>>>Universidad Nacional
>>>>>>Apartado 1350-3000
>>>>>>Heredia
>>>>>>COSTA RICA
>>>>>>[hidden email]
>>>>>>[hidden email]
>>>>>>Teléfono: (506) 2277-3598
>>>>>>Fax: (506) 2237-7036
>>>>>>Personal website: Lobito de río
>>>>>>Institutional website: ICOMVIS
>>>>
>>>>
>>>>--
>>>>Manuel Spínola, Ph.D.
>>>>Instituto Internacional en Conservación y Manejo de Vida Silvestre
>>>>Universidad Nacional
>>>>Apartado 1350-3000
>>>>Heredia
>>>>COSTA RICA
>>>>[hidden email]
>>>>[hidden email]
>>>>Teléfono: (506) 2277-3598
>>>>Fax: (506) 2237-7036
>>>>Personal website: Lobito de río
>>>>Institutional website: ICOMVIS
>>
>>
>>--
>>Manuel Spínola, Ph.D.
>>Instituto Internacional en Conservación y Manejo de Vida Silvestre
>>Universidad Nacional
>>Apartado 1350-3000
>>Heredia
>>COSTA RICA
>>[hidden email]
>>[hidden email]
>>Teléfono: (506) 2277-3598
>>Fax: (506) 2237-7036
>>Personal website: Lobito de río
>>Institutional website: ICOMVIS

--
Manuel Spínola, Ph.D.
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
[hidden email]
[hidden email]
Teléfono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de río
Institutional website: ICOMVIS --
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 [hidden email]
To unsubscribe: email [hidden email]
More options: http://groups.google.com/group/ggplot2

        [[alternative HTML version deleted]]


______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: another question on shapefiles and geom_point in ggplot2

Pierre Roudier
Hi all,

2011/4/4 Felipe Carrillo <[hidden email]>:

> 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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: another question on shapefiles and geom_point in ggplot2

dicko ahmadou
Hi all
Just as Pierre pointed out, i used rgeos instead of gpclib (the licence is
less restrictive even though i'm still students). A since the last release
the rgeos package seems to work well.
I'm really disapointed by the fact that some packages (e.g adehabitatMA
which is great thank's M. Calenge) still use gpclib and don't  offer the
possibility to switch to rgeos, and is really messy to have two package to
do the same task and with the same function name in the path (eg when  i use
adehabitatMA and maptools).

Manuel:
May be you should use the *colour* aesthetic instead of* *the* fill *one* *in
the call of *geom_path*. Something like that :

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, *colour=id*
),data=fortify.ai_biotica)

not tested, so i'm not really sure about this one

2011/4/4 Pierre Roudier <[hidden email]>

> Hi all,
>
> 2011/4/4 Felipe Carrillo <[hidden email]>:
> > 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
>
> --
> 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 [hidden email]
> To unsubscribe: email [hidden email]
> More options: http://groups.google.com/group/ggplot2
>
        [[alternative HTML version deleted]]


______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: another question on shapefiles and geom_point in ggplot2

Manuel Spínola-2
Thank you Ahmadou,

I got an error when I change fill to colour:

 > p + geom_point(aes(size = ACE, colour = ACE)) + theme_bw() +
+  scale_size(to = c(3, 15), name = "Número de especies", breaks = c(10,
40, 70, 100, 130, 160, 190, 220, 250)) +
+  scale_colour_gradientn(name = 'Número de especies', colours =
heat.colors(9), breaks = c(10, 40, 70, 100, 130, 160, 190, 220, 250)) +
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,
colour=id),data=fortify.ai_biotica)
Error: Non-continuous variable supplied to scale_colour_gradientn.

Best,

Manuel

On 04/04/2011 03:37 a.m., ahmadou dicko wrote:

> Hi all
> Just as Pierre pointed out, i used rgeos instead of gpclib (the
> licence is less restrictive even though i'm still students). A since
> the last release the rgeos package seems to work well.
> I'm really disapointed by the fact that some packages (e.g
> adehabitatMA which is great thank's M. Calenge) still use gpclib and
> don't  offer the possibility to switch to rgeos, and is really messy
> to have two package to do the same task and with the same function
> name in the path (eg when  i use adehabitatMA and maptools).
>
> Manuel:
> May be you should use the *colour* aesthetic instead of**the*fill
> *one**in the call of *geom_path*. Something like that :
>
> 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,
> *colour=id*),data=fortify.ai_biotica)
>
> not tested, so i'm not really sure about this one
>
> 2011/4/4 Pierre Roudier <[hidden email]
> <mailto:[hidden email]>>
>
>     Hi all,
>
>     2011/4/4 Felipe Carrillo <[hidden email]
>     <mailto:[hidden email]>>:
>     > 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
>
>     --
>     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 [hidden email]
>     <mailto:[hidden email]>
>     To unsubscribe: email [hidden email]
>     <mailto:ggplot2%[hidden email]>
>     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
[hidden email]
[hidden email]
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/>

        [[alternative HTML version deleted]]


______________________________________________
[hidden email] 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.