Re: [R] Plotting data on a map
Did you check the "Spatial" task view page? https://cran.r-project.org/web/views/Spatial.html Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Apr 6, 2016 at 2:20 AM,wrote: > Hello, > > I would like to generate a small map (say 10cm x 10cm) of France showing > cumulative numbers by Distribution Center > stored in a database: > > DISTRIBUTION_CENTER COUNT > Paris 122 > Paris 3 > Paris 21 > Lyon12 > Lyon > Lyon33 > Grenoble55 > Grenoble999 > Grenoble99 > ... > > I have looked at different graphing packages such as 'sp', 'raster' and > 'ggplot2', but am not sure which one is most > appropriate for my purposes. Furthermore, I don't understand how you retrieve > city coordinates from shp, gadm, etc., maps > generated, or downloaded from the web and then processed, with those packages > (SHP, GADM, etc.), and plot data at those coordinates. > > Any help would be much appreciated. > > Many thanks. > > Philippe > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Plotting data on a map
Some tutorials and examples may help. http://www.zoology.ubc.ca/~kgilbert/mysite/Miscellaneous_files/R_MakingMaps.pdf http://coulmont.com/cartes/rcarto.pdf https://pakillo.github.io/R-GIS-tutorial/ http://www.milanor.net/blog/maps-in-r-plotting-data-points-on-a-map/ https://www.youtube.com/watch?v=PTti7OMbURo https://www.nceas.ucsb.edu/scicomp/usecases/CreateMapsWithRGraphics -- Best, GG [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Plotting data on a map
Hello, I would like to generate a small map (say 10cm x 10cm) of France showing cumulative numbers by Distribution Center stored in a database: DISTRIBUTION_CENTER COUNT Paris 122 Paris 3 Paris 21 Lyon12 Lyon Lyon33 Grenoble55 Grenoble999 Grenoble99 ... I have looked at different graphing packages such as 'sp', 'raster' and 'ggplot2', but am not sure which one is most appropriate for my purposes. Furthermore, I don't understand how you retrieve city coordinates from shp, gadm, etc., maps generated, or downloaded from the web and then processed, with those packages (SHP, GADM, etc.), and plot data at those coordinates. Any help would be much appreciated. Many thanks. Philippe __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Plotting Data on a Map
Upload it to GoogleDocs http://docs.google.com or Dropboxhttp://dropbox.comand give us a public link to the dataset. HTH, Brandon On Wed, Jun 23, 2010 at 21:57, Felipe Carrillo mazatlanmex...@yahoo.comwrote: For some reason the shapefile can't get attached. The shapefile is too large to put it in dput..Is there another way to do this? - Original Message From: Felipe Carrillo mazatlanmex...@yahoo.com To: Tom Hopper tomhop...@gmail.com Cc: r-h...@stat.math.ethz.ch; ggpl...@googlegroups.com Sent: Wed, June 23, 2010 1:52:29 PM Subject: Re: [R] Plotting Data on a Map Hi: I am practicing with the attached shapefile and was wondering if I can get some help. Haven't used 'rgdal' and 'maptools' much but it appears to be a great way bring map data into R. Please take a look at the comments and let me know if I need to explain better what I am trying to accomplish. library(rgdal) library(maptools) library(ggplot2) dsn=C:/Documents and Settings/fcarrillo/Desktop/Software/R Scripts and Datasets/NCTC/Data Analisys II/Data 4 Data Analysis II March 2009- March2010/Data wolves.map - readOGR(dsn=dsn, layer=PNW_wolf_habitat_grid) class(wolves.map) dim(wolves.map) head(wolves.map,1) names(wolves.map) gpclibPermit() wolves.ds - fortify(wolves.map) head(wolves.ds);tail(wolves.ds) # Shapefile of 5 states wolves.plot - ggplot(wolves.ds,aes(long,lat,group=group)) + geom_polygon(colour='white',fill='lightblue') wolves.plot # How to show the state borders of Washington, Oregon, Idaho, Montana and Wyoming on map? # Subset from wolves to create a logistic regression model based on WOLVES_99 and then apply to all the 5 states # Remove the WOLVES_99 2(two value) and use one for presence and zero for absence to end up with 153 records. #wolfsub-subset(wolves,subset=!(WOLVES_99==2)) #wolfsub - subset(wolves.map,WOLVES_99!=2) wolfsub - wolves.map[!wolves.map$WOLVES_99 %in% 2,];wolfsub dim(wolfsub) # 42 = Forest, 51 = Shrub, 81 = Agriculture wolfsub$Forest-ifelse(wolfsub$MAJOR_LC==42,1,0) wolfsub$Shrub-ifelse(wolfsub$MAJOR_LC==51,1,0) wolfsub$Agriculture-ifelse(wolfsub$MAJOR_LC81,1,0) names(wolfsub);dim(wolfsub) # create the model mod1-glm(WOLVES_99~RD_DENSITY+Forest+Shrub +Agriculture,family=binomial,data=wolfsub) summary(mod1) wolfsub$pred99-fitted(mod1) names(wolfsub) #fitted(mod1) wolfsub$pred99 # Add the wolfsub data to the map to see the map wolfsub - fortify(wolfsub);names(wolfsub) area_mod - wolves.plot + geom_polygon(data=wolfsub,aes(fill=)) #Want to fill by WOLVES_99 but is gone #after fortify area_mod #Not sure how to proceed from here to fit the 'mod1' model to all #the 5 states. From: Tom Hopper href=mailto:tomhop...@gmail.com;tomhop...@gmail.com To: Felipe Carrillo href=mailto:mazatlanmex...@yahoo.com; mazatlanmex...@yahoo.com Sent: Tue, June 22, 2010 9:40:19 PM Subject: Re: Plotting Data on a Map Felipe, I am just learning these tools, too, so it may be a good learning opportunity for both of us. Please send me the files and I will try to put it together and plot it. Regards, Tom On Mon, Jun 21, 2010 at 11:57 PM, Felipe Carrillo ymailto=mailto: mazatlanmex...@yahoo.com href=mailto:mazatlanmex...@yahoo.com;mazatlanmex...@yahoo.com wrote: Hi Tom: I am just starting to use rgdal and maptools but I have a long way to go. I went to a training a couple of weeks ago and the instructor showed us a csv file and a shapefile with wolf data from a national park in the midwest. I am trying to put all of the csv data and some predicted data on a map using ggplot2 but I am stuck with it. I am just trying to do this example because I want to see if I can apply this example to fish. Let me know if interested. Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA From: Tom Hopper href=mailto:tomhop...@gmail.com;tomhop...@gmail.com To: href=mailto:ggpl...@googlegroups.com;ggpl...@googlegroups.com Sent: Mon, June 21, 2010 2:27:14 PM Subject: Re: Plotting Data on a Map Hadley, Thank you! I doing this, I've encountered an encountered and unexpected difference between the graphs on my Mac and my Windows machines. It appears that there is a default setting different between the two programs. Using the same commands on both Mac and Windows, I found that the polygon borders are plotted on the Mac, but not on Windows, so on the Mac I see the country borders, but on Windows I do not. On the Mac, it looks like the default for geom_polygon is something like size = 0.01, colour = gray50. On Windows, it's more like colour = alpha(gray50, 0), though in fact the visibility of polygon borders seems to be independent of both the size and colour settings. Regards, Tom
Re: [R] Plotting Data on a Map
Hi: I am practicing with the attached shapefile and was wondering if I can get some help. Haven't used 'rgdal' and 'maptools' much but it appears to be a great way bring map data into R. Please take a look at the comments and let me know if I need to explain better what I am trying to accomplish. library(rgdal) library(maptools) library(ggplot2) dsn=C:/Documents and Settings/fcarrillo/Desktop/Software/R Scripts and Datasets/NCTC/Data Analisys II/Data 4 Data Analysis II March 2009- March2010/Data wolves.map - readOGR(dsn=dsn, layer=PNW_wolf_habitat_grid) class(wolves.map) dim(wolves.map) head(wolves.map,1) names(wolves.map) gpclibPermit() wolves.ds - fortify(wolves.map) head(wolves.ds);tail(wolves.ds) # Shapefile of 5 states wolves.plot - ggplot(wolves.ds,aes(long,lat,group=group)) + geom_polygon(colour='white',fill='lightblue') wolves.plot # How to show the state borders of Washington, Oregon, Idaho, Montana and Wyoming on map? # Subset from wolves to create a logistic regression model based on WOLVES_99 and then apply to all the 5 states # Remove the WOLVES_99 2(two value) and use one for presence and zero for absence to end up with 153 records. #wolfsub-subset(wolves,subset=!(WOLVES_99==2)) #wolfsub - subset(wolves.map,WOLVES_99!=2) wolfsub - wolves.map[!wolves.map$WOLVES_99 %in% 2,];wolfsub dim(wolfsub) # 42 = Forest, 51 = Shrub, 81 = Agriculture wolfsub$Forest-ifelse(wolfsub$MAJOR_LC==42,1,0) wolfsub$Shrub-ifelse(wolfsub$MAJOR_LC==51,1,0) wolfsub$Agriculture-ifelse(wolfsub$MAJOR_LC81,1,0) names(wolfsub);dim(wolfsub) # create the model mod1-glm(WOLVES_99~RD_DENSITY+Forest+Shrub +Agriculture,family=binomial,data=wolfsub) summary(mod1) wolfsub$pred99-fitted(mod1) names(wolfsub) #fitted(mod1) wolfsub$pred99 # Add the wolfsub data to the map to see the map wolfsub - fortify(wolfsub);names(wolfsub) area_mod - wolves.plot + geom_polygon(data=wolfsub,aes(fill=)) #Want to fill by WOLVES_99 but is gone #after fortify area_mod #Not sure how to proceed from here to fit the 'mod1' model to all #the 5 states. From: Tom Hopper tomhop...@gmail.com To: Felipe Carrillo mazatlanmex...@yahoo.com Sent: Tue, June 22, 2010 9:40:19 PM Subject: Re: Plotting Data on a Map Felipe, I am just learning these tools, too, so it may be a good learning opportunity for both of us. Please send me the files and I will try to put it together and plot it. Regards, Tom On Mon, Jun 21, 2010 at 11:57 PM, Felipe Carrillo mazatlanmex...@yahoo.com wrote: Hi Tom: I am just starting to use rgdal and maptools but I have a long way to go. I went to a training a couple of weeks ago and the instructor showed us a csv file and a shapefile with wolf data from a national park in the midwest. I am trying to put all of the csv data and some predicted data on a map using ggplot2 but I am stuck with it. I am just trying to do this example because I want to see if I can apply this example to fish. Let me know if interested. Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA From: Tom Hopper tomhop...@gmail.com To: ggpl...@googlegroups.com Sent: Mon, June 21, 2010 2:27:14 PM Subject: Re: Plotting Data on a Map Hadley, Thank you! I doing this, I've encountered an encountered and unexpected difference between the graphs on my Mac and my Windows machines. It appears that there is a default setting different between the two programs. Using the same commands on both Mac and Windows, I found that the polygon borders are plotted on the Mac, but not on Windows, so on the Mac I see the country borders, but on Windows I do not. On the Mac, it looks like the default for geom_polygon is something like size = 0.01, colour = gray50. On Windows, it's more like colour = alpha(gray50, 0), though in fact the visibility of polygon borders seems to be independent of both the size and colour settings. Regards, Tom On Mon, Jun 21, 2010 at 3:00 AM, Hadley Wickham had...@rice.edu wrote: Hi Tom, Thanks for contribution! Ploting map data is never easy and its always nice to see a success story. Hadley On Saturday, June 19, 2010, Tom Hopper tomhop...@gmail.com wrote: Well, it turns out that, in my haste to thank Fernando, I posted code with some typos. I have also had a chance to test it on my Mac, and found that fortify() was throwing an error (Error in nchar(ID) : invalid multibyte string 1). I have added a call, currently commented out, to Sys.setlocale() to fix this. I have tested the code below under R 2.11.1 on both Windows XP and Mac OS X 10.5.8, with the latest packages installed. In fact, the plot looks better in the Mac Quartz window. Sorry for the previous errors. # Download electricity generation data from http://tonto.eia.doe.gov/cfapps/ipdbproject/iedindex3.cfm?tid=2pid=2aid=12cid=syid=2004eyid=2008unit=BKWH # Download new map data from http://thematicmapping.org/downloads/world_borders.php # Bring the
Re: [R] Plotting Data on a Map
For some reason the shapefile can't get attached. The shapefile is too large to put it in dput..Is there another way to do this? - Original Message From: Felipe Carrillo mazatlanmex...@yahoo.com To: Tom Hopper tomhop...@gmail.com Cc: r-h...@stat.math.ethz.ch; ggpl...@googlegroups.com Sent: Wed, June 23, 2010 1:52:29 PM Subject: Re: [R] Plotting Data on a Map Hi: I am practicing with the attached shapefile and was wondering if I can get some help. Haven't used 'rgdal' and 'maptools' much but it appears to be a great way bring map data into R. Please take a look at the comments and let me know if I need to explain better what I am trying to accomplish. library(rgdal) library(maptools) library(ggplot2) dsn=C:/Documents and Settings/fcarrillo/Desktop/Software/R Scripts and Datasets/NCTC/Data Analisys II/Data 4 Data Analysis II March 2009- March2010/Data wolves.map - readOGR(dsn=dsn, layer=PNW_wolf_habitat_grid) class(wolves.map) dim(wolves.map) head(wolves.map,1) names(wolves.map) gpclibPermit() wolves.ds - fortify(wolves.map) head(wolves.ds);tail(wolves.ds) # Shapefile of 5 states wolves.plot - ggplot(wolves.ds,aes(long,lat,group=group)) + geom_polygon(colour='white',fill='lightblue') wolves.plot # How to show the state borders of Washington, Oregon, Idaho, Montana and Wyoming on map? # Subset from wolves to create a logistic regression model based on WOLVES_99 and then apply to all the 5 states # Remove the WOLVES_99 2(two value) and use one for presence and zero for absence to end up with 153 records. #wolfsub-subset(wolves,subset=!(WOLVES_99==2)) #wolfsub - subset(wolves.map,WOLVES_99!=2) wolfsub - wolves.map[!wolves.map$WOLVES_99 %in% 2,];wolfsub dim(wolfsub) # 42 = Forest, 51 = Shrub, 81 = Agriculture wolfsub$Forest-ifelse(wolfsub$MAJOR_LC==42,1,0) wolfsub$Shrub-ifelse(wolfsub$MAJOR_LC==51,1,0) wolfsub$Agriculture-ifelse(wolfsub$MAJOR_LC81,1,0) names(wolfsub);dim(wolfsub) # create the model mod1-glm(WOLVES_99~RD_DENSITY+Forest+Shrub +Agriculture,family=binomial,data=wolfsub) summary(mod1) wolfsub$pred99-fitted(mod1) names(wolfsub) #fitted(mod1) wolfsub$pred99 # Add the wolfsub data to the map to see the map wolfsub - fortify(wolfsub);names(wolfsub) area_mod - wolves.plot + geom_polygon(data=wolfsub,aes(fill=)) #Want to fill by WOLVES_99 but is gone #after fortify area_mod #Not sure how to proceed from here to fit the 'mod1' model to all #the 5 states. From: Tom Hopper href=mailto:tomhop...@gmail.com;tomhop...@gmail.com To: Felipe Carrillo href=mailto:mazatlanmex...@yahoo.com;mazatlanmex...@yahoo.com Sent: Tue, June 22, 2010 9:40:19 PM Subject: Re: Plotting Data on a Map Felipe, I am just learning these tools, too, so it may be a good learning opportunity for both of us. Please send me the files and I will try to put it together and plot it. Regards, Tom On Mon, Jun 21, 2010 at 11:57 PM, Felipe Carrillo ymailto=mailto:mazatlanmex...@yahoo.com; href=mailto:mazatlanmex...@yahoo.com;mazatlanmex...@yahoo.com wrote: Hi Tom: I am just starting to use rgdal and maptools but I have a long way to go. I went to a training a couple of weeks ago and the instructor showed us a csv file and a shapefile with wolf data from a national park in the midwest. I am trying to put all of the csv data and some predicted data on a map using ggplot2 but I am stuck with it. I am just trying to do this example because I want to see if I can apply this example to fish. Let me know if interested. Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA From: Tom Hopper href=mailto:tomhop...@gmail.com;tomhop...@gmail.com To: href=mailto:ggpl...@googlegroups.com;ggpl...@googlegroups.com Sent: Mon, June 21, 2010 2:27:14 PM Subject: Re: Plotting Data on a Map Hadley, Thank you! I doing this, I've encountered an encountered and unexpected difference between the graphs on my Mac and my Windows machines. It appears that there is a default setting different between the two programs. Using the same commands on both Mac and Windows, I found that the polygon borders are plotted on the Mac, but not on Windows, so on the Mac I see the country borders, but on Windows I do not. On the Mac, it looks like the default for geom_polygon is something like size = 0.01, colour = gray50. On Windows, it's more like colour = alpha(gray50, 0), though in fact the visibility of polygon borders seems to be independent of both the size and colour settings. Regards, Tom On Mon, Jun 21, 2010 at 3:00 AM, Hadley Wickham ymailto=mailto:had...@rice.edu; href=mailto:had...@rice.edu;had...@rice.edu wrote: Hi Tom, Thanks for contribution! Ploting map data is never easy and its always nice to see a success story. Hadley On Saturday, June 19, 2010, Tom Hopper href=mailto:tomhop
Re: [R] Plotting Data on a Map
On Jun 23, 2010, at 4:57 PM, Felipe Carrillo wrote: For some reason the shapefile can't get attached. The shapefile is too large to put it in dput..Is there another way to do this? If you dput or dump it and then label the output as sth.txt it will generally pass the server's scrutiny. -- David. - Original Message From: Felipe Carrillo mazatlanmex...@yahoo.com To: Tom Hopper tomhop...@gmail.com Cc: r-h...@stat.math.ethz.ch; ggpl...@googlegroups.com Sent: Wed, June 23, 2010 1:52:29 PM Subject: Re: [R] Plotting Data on a Map Hi: I am practicing with the attached shapefile and was wondering if I can get some help. Haven't used 'rgdal' and 'maptools' much but it appears to be a great way bring map data into R. Please take a look at the comments and let me know if I need to explain better what I am trying to accomplish. library(rgdal) library(maptools) library(ggplot2) dsn=C:/Documents and Settings/fcarrillo/Desktop/Software/R Scripts and Datasets/NCTC/Data Analisys II/Data 4 Data Analysis II March 2009- March2010/Data wolves.map - readOGR(dsn=dsn, layer=PNW_wolf_habitat_grid) class(wolves.map) dim(wolves.map) head(wolves.map,1) names(wolves.map) gpclibPermit() wolves.ds - fortify(wolves.map) head(wolves.ds);tail(wolves.ds) # Shapefile of 5 states wolves.plot - ggplot(wolves.ds,aes(long,lat,group=group)) + geom_polygon(colour='white',fill='lightblue') wolves.plot # How to show the state borders of Washington, Oregon, Idaho, Montana and Wyoming on map? # Subset from wolves to create a logistic regression model based on WOLVES_99 and then apply to all the 5 states # Remove the WOLVES_99 2(two value) and use one for presence and zero for absence to end up with 153 records. #wolfsub-subset(wolves,subset=!(WOLVES_99==2)) #wolfsub - subset(wolves.map,WOLVES_99!=2) wolfsub - wolves.map[!wolves.map$WOLVES_99 %in% 2,];wolfsub dim(wolfsub) # 42 = Forest, 51 = Shrub, 81 = Agriculture wolfsub$Forest-ifelse(wolfsub$MAJOR_LC==42,1,0) wolfsub$Shrub-ifelse(wolfsub$MAJOR_LC==51,1,0) wolfsub$Agriculture-ifelse(wolfsub$MAJOR_LC81,1,0) names(wolfsub);dim(wolfsub) # create the model mod1-glm(WOLVES_99~RD_DENSITY+Forest+Shrub +Agriculture,family=binomial,data=wolfsub) summary(mod1) wolfsub$pred99-fitted(mod1) names(wolfsub) #fitted(mod1) wolfsub$pred99 # Add the wolfsub data to the map to see the map wolfsub - fortify(wolfsub);names(wolfsub) area_mod - wolves.plot + geom_polygon(data=wolfsub,aes(fill=)) #Want to fill by WOLVES_99 but is gone #after fortify area_mod #Not sure how to proceed from here to fit the 'mod1' model to all #the 5 states. From: Tom Hopper href=mailto:tomhop...@gmail.com;tomhop...@gmail.com To: Felipe Carrillo href=mailto:mazatlanmex...@yahoo.com;mazatlanmex...@yahoo.com Sent: Tue, June 22, 2010 9:40:19 PM Subject: Re: Plotting Data on a Map Felipe, I am just learning these tools, too, so it may be a good learning opportunity for both of us. Please send me the files and I will try to put it together and plot it. Regards, Tom On Mon, Jun 21, 2010 at 11:57 PM, Felipe Carrillo ymailto=mailto:mazatlanmex...@yahoo.com href=mailto:mazatlanmex...@yahoo.com;mazatlanmex...@yahoo.com wrote: Hi Tom: I am just starting to use rgdal and maptools but I have a long way to go. I went to a training a couple of weeks ago and the instructor showed us a csv file and a shapefile with wolf data from a national park in the midwest. I am trying to put all of the csv data and some predicted data on a map using ggplot2 but I am stuck with it. I am just trying to do this example because I want to see if I can apply this example to fish. Let me know if interested. Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA From: Tom Hopper href=mailto:tomhop...@gmail.com;tomhop...@gmail.com To: href=mailto:ggpl...@googlegroups.com;ggpl...@googlegroups.com Sent: Mon, June 21, 2010 2:27:14 PM Subject: Re: Plotting Data on a Map Hadley, Thank you! I doing this, I've encountered an encountered and unexpected difference between the graphs on my Mac and my Windows machines. It appears that there is a default setting different between the two programs. Using the same commands on both Mac and Windows, I found that the polygon borders are plotted on the Mac, but not on Windows, so on the Mac I see the country borders, but on Windows I do not. On the Mac, it looks like the default for geom_polygon is something like size = 0.01, colour = gray50. On Windows, it's more like colour = alpha(gray50, 0), though in fact the visibility of polygon borders seems to be independent of both the size and colour settings. Regards, Tom On Mon, Jun 21, 2010 at 3:00 AM, Hadley Wickham ymailto=mailto:had...@rice.edu href=mailto:had...@rice.edu;had...@rice.edu wrote: Hi Tom, Thanks for contribution! Ploting map data