Re: [R] adjusting the map of France to 1830
> Date: Fri, 19 Nov 2004 15:59:25 -0500 > From: Michael Friendly <[EMAIL PROTECTED]> > > Here's what I tried. I can plot a selection of regions, but I > can't seem to remove an arbitrary list of region numbers, unless I've > done something wrong > by selecting the regions I want to plot with departements[-exclude]. I think here the problemis not using exact=T in the call to map(), see below. > I also get an error > when I try to use map.text to label a map with only the regions I'm > selecting. > > > departements <- map('france',namesonly=T, plot=FALSE) > > # returns a vector of names of regions > > > > exclude <- c(47, #Alpes-Maritimes > + 66, # Haute-Savoie > + 76, # Savoie > + 95, # Territore-de-Belfort > + 109, 110, 111, # Var: Iles d'Hyeres > + 49, 53, 54, 55, # Moribhan: Isles > + 62, 64,# Vendee: Isles > + 72, 75 # Charente-Maritime: Isles > + ) > > > > depts <- departements[-exclude] > > gfrance <-map('france', regions=depts) > > labels <- (as.character(1:length(departements)))[-exclude] > > gfrance <-map.text('france', regions=depts, add=FALSE, labels=labels) > Error in map.text("france", regions = depts, add = FALSE, labels = labels) : > map object must have polygons (fill=TRUE) > That error message is issued when regions= specifies less than the whole database, in which case the alternate "list of 'x', 'y', and 'names' obtained from a previous call to 'map'" is required as a first parameter. So to do what you want (notwithstanding the next problem you raise), try the following as a demonstration: gfrance <- map('france', regions=depts, exact=T, fill=T, plot=F) map.text(gfrance, regions=depts, labels=labels) map('france', regions=departements[exclude], fill=T, col=1, add=T) > Another problem, potentially more difficult for mapping data on the map > of France is that > the "departements" are actually just the polygons in the map, > arbitrarily numbered from > east to west, and from north to south --- they don't correspond to the > 'official' administrative > region numbers. As well, the departement names don't always match > exactly (ignoring > accents, e.g., Val-d'Oise vs. Val-Doise) so it would be another > challenge to plot my > historical data on the map of France. > Well, maps is a source package! [:-)]. You are most welcome to modify the source files maps/src/france.{gon,line,name} to reorder the polygons (and correct errors in the names). If the relationship between those 3 files is not obvious, contact me for further details. Also, I am happy to fold your changes back into the original maps package. Ray Brownrigg __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] adjusting the map of France to 1830
Hello Michael, you have made a small mystake in your code: use gfrance <-map.text('france', regions=depts, add=FALSE) But I think that, it would be quite difficult to do what you need in R. It is more a GIS problem. I think that your problem can be better treated if you can create your map outside R and import it. The map is freely available at: http://www.ign.fr/affiche_rubrique.asp?rbr_id=1761&lng_id=FR#71023 it contains administrative numbers... You can modify the map in a GIS, (e.g. ArcView) and import it with maptools package. Tell me if you can do the GIS part, otherwise I can do the job (it is is not too long ;-) ) and send you the "old france" data ! Sincerely, At 15:59 19/11/2004, you wrote: Here's what I tried. I can plot a selection of regions, but I can't seem to remove an arbitrary list of region numbers, unless I've done something wrong by selecting the regions I want to plot with departements[-exclude]. I also get an error when I try to use map.text to label a map with only the regions I'm selecting. > departements <- map('france',namesonly=T, plot=FALSE) > # returns a vector of names of regions > > exclude <- c(47, #Alpes-Maritimes + 66, # Haute-Savoie + 76, # Savoie + 95, # Territore-de-Belfort + 109, 110, 111, # Var: Iles d'Hyeres + 49, 53, 54, 55, # Moribhan: Isles + 62, 64,# Vendee: Isles + 72, 75 # Charente-Maritime: Isles + ) > > depts <- departements[-exclude] > gfrance <-map('france', regions=depts) > labels <- (as.character(1:length(departements)))[-exclude] > gfrance <-map.text('france', regions=depts, add=FALSE, labels=labels) Error in map.text("france", regions = depts, add = FALSE, labels = labels) : map object must have polygons (fill=TRUE) Another problem, potentially more difficult for mapping data on the map of France is that the "departements" are actually just the polygons in the map, arbitrarily numbered from east to west, and from north to south --- they don't correspond to the 'official' administrative region numbers. As well, the departement names don't always match exactly (ignoring accents, e.g., Val-d'Oise vs. Val-Doise) so it would be another challenge to plot my historical data on the map of France. -Michael Stephane DRAY wrote: Hello. I do not know if you can merge polygons, but you can select easily: > departements=map('france',namesonly=T) # returns a vector of names of regions > map('france',regions=departements[1:20],namesonly=T) # use what you need with regions argument Hope this helps, At 16:29 18/11/2004, Michael Friendly wrote: I'm doing some analyses of historical data from France in 1830 on 'moral statistics' that I'd like to show on a map. I've done most of my analyses in SAS, but a few things would work better in R. To do this, I have to adjust the modern map, library(maps) map('france') to adjust for changes in departments (86 in 1830, to 97 now). I've read the documentation for the maps and maptools package, but there seems to be no functions to allow this, and I can't find information on the exact structure of map datasets, but I understand them to be delimited lists of polygon coordinates. In SAS, all maps have (one or more) ID variables representing the geographical region, and there is also a proc gremove that can remove internal boundaries inside the polygons for regions with the same ID. Is there some way I can do this in R? Here's what I did in SAS: *-- Fix the map of France to conform to Guerry: - adjust the 97 current departments to correspond to the 86 in 1830 - delete those not part of France then ; data gfrtemp; set maps.france; /* Corse was one dept - merge these to one area, new ID */ if id in (201, 202)then dept=200; /* Seine et Oise (78) was cut into Essonne (91), Val d'Oise (95) and Yvelines (78) */ else if id in (91, 95)then dept=78; /* Seine (75) now split into Hauts-de-Seine (92), Seine-Saint-Denis (93) et Val-de-Marne (94)*/ else if id in (92, 93, 94)then dept=75; /* departments not part of France in 1830 */ else if id in ( 6, /* Alpes-Maritimes */ 73,74, /* Savoie, Haute-Savoie */ 90)/* Territore-de-Belfort */ then delete; else dept=id; run; *-- remove internal boundaries based on merged DEPT; proc sort data=gfrtemp; by dept; proc gremove data=gfrtemp out=gfrance; by dept; id id; run; -- Michael Friendly Email: [EMAIL PROTECTED] Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Streethttp://www.math.yorku.ca/SCS/friendly.html Toronto, ONT M3J 1P3 CANADA __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Stéphane DRAY -- Département des Sciences
Re: [R] adjusting the map of France to 1830
Here's what I tried. I can plot a selection of regions, but I can't seem to remove an arbitrary list of region numbers, unless I've done something wrong by selecting the regions I want to plot with departements[-exclude]. I also get an error when I try to use map.text to label a map with only the regions I'm selecting. > departements <- map('france',namesonly=T, plot=FALSE) > # returns a vector of names of regions > > exclude <- c(47, #Alpes-Maritimes + 66, # Haute-Savoie + 76, # Savoie + 95, # Territore-de-Belfort + 109, 110, 111, # Var: Iles d'Hyeres + 49, 53, 54, 55, # Moribhan: Isles + 62, 64,# Vendee: Isles + 72, 75 # Charente-Maritime: Isles + ) > > depts <- departements[-exclude] > gfrance <-map('france', regions=depts) > labels <- (as.character(1:length(departements)))[-exclude] > gfrance <-map.text('france', regions=depts, add=FALSE, labels=labels) Error in map.text("france", regions = depts, add = FALSE, labels = labels) : map object must have polygons (fill=TRUE) Another problem, potentially more difficult for mapping data on the map of France is that the "departements" are actually just the polygons in the map, arbitrarily numbered from east to west, and from north to south --- they don't correspond to the 'official' administrative region numbers. As well, the departement names don't always match exactly (ignoring accents, e.g., Val-d'Oise vs. Val-Doise) so it would be another challenge to plot my historical data on the map of France. -Michael Stephane DRAY wrote: Hello. I do not know if you can merge polygons, but you can select easily: > departements=map('france',namesonly=T) # returns a vector of names of regions > map('france',regions=departements[1:20],namesonly=T) # use what you need with regions argument Hope this helps, At 16:29 18/11/2004, Michael Friendly wrote: I'm doing some analyses of historical data from France in 1830 on 'moral statistics' that I'd like to show on a map. I've done most of my analyses in SAS, but a few things would work better in R. To do this, I have to adjust the modern map, library(maps) map('france') to adjust for changes in departments (86 in 1830, to 97 now). I've read the documentation for the maps and maptools package, but there seems to be no functions to allow this, and I can't find information on the exact structure of map datasets, but I understand them to be delimited lists of polygon coordinates. In SAS, all maps have (one or more) ID variables representing the geographical region, and there is also a proc gremove that can remove internal boundaries inside the polygons for regions with the same ID. Is there some way I can do this in R? Here's what I did in SAS: *-- Fix the map of France to conform to Guerry: - adjust the 97 current departments to correspond to the 86 in 1830 - delete those not part of France then ; data gfrtemp; set maps.france; /* Corse was one dept - merge these to one area, new ID */ if id in (201, 202)then dept=200; /* Seine et Oise (78) was cut into Essonne (91), Val d'Oise (95) and Yvelines (78) */ else if id in (91, 95)then dept=78; /* Seine (75) now split into Hauts-de-Seine (92), Seine-Saint-Denis (93) et Val-de-Marne (94)*/ else if id in (92, 93, 94)then dept=75; /* departments not part of France in 1830 */ else if id in ( 6, /* Alpes-Maritimes */ 73,74, /* Savoie, Haute-Savoie */ 90)/* Territore-de-Belfort */ then delete; else dept=id; run; *-- remove internal boundaries based on merged DEPT; proc sort data=gfrtemp; by dept; proc gremove data=gfrtemp out=gfrance; by dept; id id; run; -- Michael Friendly Email: [EMAIL PROTECTED] Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Streethttp://www.math.yorku.ca/SCS/friendly.html Toronto, ONT M3J 1P3 CANADA __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Stéphane DRAY -- Département des Sciences Biologiques Université de Montréal, C.P. 6128, succursale centre-ville Montréal, Québec H3C 3J7, Canada Tel : (514) 343-6111 poste 1233 Fax : (514) 343-2293 E-mail : [EMAIL PROTECTED] -- Web http://www.steph280.freesurf.fr/ -- -- Michael Friendly Email: [EMAIL PROTECTED] Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Streethttp://www.math.yorku.ca/SCS/friendly.html Toronto, ONT M3J 1P3 CANA
Re: [R] adjusting the map of France to 1830
At 19:07 18/11/2004, Ray Brownrigg wrote: At 16:29 18/11/2004, Michael Friendly wrote: > I'm doing some analyses of historical data from France in 1830 on 'moral > statistics' that I'd like to > show on a map. I've done most of my analyses in SAS, but a few things > would work better in R. > To do this, I have to adjust the modern map, > > library(maps) > map('france') > > to adjust for changes in departments (86 in 1830, to 97 now). I've read > the documentation > for the maps and maptools package, but there seems to be no functions to > allow this, and > I can't find information on the exact structure of map datasets, but I > understand them to > be delimited lists of polygon coordinates. > > In SAS, all maps have (one or more) ID variables representing the > geographical region, > and there is also a proc gremove that can remove internal boundaries > inside the polygons > for regions with the same ID. Is there some way I can do this in R? > Unfortunately not with the current implementation of several of the 'extra' databases in the mapdata package. The map() function does have the interior=FALSE option, which would normally do what you want, but only when the data has been manipulated to allow it. Currently this option is only useful with the world and usa maps (and their derivatives, such as world2 and state). Currently every department is a complete polygon, and so every interior line segment occurs twice in the data. What has to happen to the data is for it to be split up into non-overlapping line segments, and each polygon reconstructed from a list of these line segments (with direction being important). There is the gpclib package which computes intersection, union... of polygons. I have try to play with its union function and the france data, but the results are good but a little bit complicate: # i merge the two firts polygons: > departements=map('france') > which(is.na(departements$x))[1:2] [1] 66 122 > gpcA <- as(cbind(departements$x[1:65],departements$y[1:65]),"gpc.poly") > gpcB <- as(cbind(departements$x[67:121],departements$y[67:121]),"gpc.poly") > union(gpcA,gpcB) GPC Polygon Num. Contours: 1 Num. Vertices: 74 BBox (X): 1.563161 --> 4.225965 BBox (Y): 49.97212 --> 51.09752 > gpcAB<-union(gpcA,gpcB) > departements$x=c(attr(gpcAB,"pts")[[1]]$x,attr(gpcAB,"pts")[[1]]$x[1],departements$x[-(1:121)]) > departements$y=c(attr(gpcAB,"pts")[[1]]$y,,attr(gpcAB,"pts")[[1]]$y[1],departements$y[-(1:121)]) > map(departements) Another solution is to do the job in a GIS and to import the new map with maptools. The package gpclib is very intersting and I think that it can be used to develop some basic GIS tools. I have write a functions to compute intersections for objects of class polys easily. The only thing is to know for which class of spatial objects these functions must be developed ! Stéphane DRAY -- Département des Sciences Biologiques Université de Montréal, C.P. 6128, succursale centre-ville Montréal, Québec H3C 3J7, Canada Tel : (514) 343-6111 poste 1233 Fax : (514) 343-2293 E-mail : [EMAIL PROTECTED] -- Web http://www.steph280.freesurf.fr/ __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] adjusting the map of France to 1830
At 16:29 18/11/2004, Michael Friendly wrote: > I'm doing some analyses of historical data from France in 1830 on 'moral > statistics' that I'd like to > show on a map. I've done most of my analyses in SAS, but a few things > would work better in R. > To do this, I have to adjust the modern map, > > library(maps) > map('france') > > to adjust for changes in departments (86 in 1830, to 97 now). I've read > the documentation > for the maps and maptools package, but there seems to be no functions to > allow this, and > I can't find information on the exact structure of map datasets, but I > understand them to > be delimited lists of polygon coordinates. > > In SAS, all maps have (one or more) ID variables representing the > geographical region, > and there is also a proc gremove that can remove internal boundaries > inside the polygons > for regions with the same ID. Is there some way I can do this in R? > Unfortunately not with the current implementation of several of the 'extra' databases in the mapdata package. The map() function does have the interior=FALSE option, which would normally do what you want, but only when the data has been manipulated to allow it. Currently this option is only useful with the world and usa maps (and their derivatives, such as world2 and state). Currently every department is a complete polygon, and so every interior line segment occurs twice in the data. What has to happen to the data is for it to be split up into non-overlapping line segments, and each polygon reconstructed from a list of these line segments (with direction being important). If you are prepared to perform this somewhat tedious process, I am happy to assist you with further details. However even with the interior= option functioning, it would still not be easy to produce the map you would require, since you would have to build it up from many components (namely each of the 'combined' departments, plus 'all the rest'). HTH, Ray Brownrigg __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] adjusting the map of France to 1830
Hello. I do not know if you can merge polygons, but you can select easily: > departements=map('france',namesonly=T) # returns a vector of names of regions > map('france',regions=departements[1:20],namesonly=T) # use what you need with regions argument Hope this helps, At 16:29 18/11/2004, Michael Friendly wrote: I'm doing some analyses of historical data from France in 1830 on 'moral statistics' that I'd like to show on a map. I've done most of my analyses in SAS, but a few things would work better in R. To do this, I have to adjust the modern map, library(maps) map('france') to adjust for changes in departments (86 in 1830, to 97 now). I've read the documentation for the maps and maptools package, but there seems to be no functions to allow this, and I can't find information on the exact structure of map datasets, but I understand them to be delimited lists of polygon coordinates. In SAS, all maps have (one or more) ID variables representing the geographical region, and there is also a proc gremove that can remove internal boundaries inside the polygons for regions with the same ID. Is there some way I can do this in R? Here's what I did in SAS: *-- Fix the map of France to conform to Guerry: - adjust the 97 current departments to correspond to the 86 in 1830 - delete those not part of France then ; data gfrtemp; set maps.france; /* Corse was one dept - merge these to one area, new ID */ if id in (201, 202)then dept=200; /* Seine et Oise (78) was cut into Essonne (91), Val d'Oise (95) and Yvelines (78) */ else if id in (91, 95)then dept=78; /* Seine (75) now split into Hauts-de-Seine (92), Seine-Saint-Denis (93) et Val-de-Marne (94)*/ else if id in (92, 93, 94)then dept=75; /* departments not part of France in 1830 */ else if id in ( 6, /* Alpes-Maritimes */ 73,74, /* Savoie, Haute-Savoie */ 90)/* Territore-de-Belfort */ then delete; else dept=id; run; *-- remove internal boundaries based on merged DEPT; proc sort data=gfrtemp; by dept; proc gremove data=gfrtemp out=gfrance; by dept; id id; run; -- Michael Friendly Email: [EMAIL PROTECTED] Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Streethttp://www.math.yorku.ca/SCS/friendly.html Toronto, ONT M3J 1P3 CANADA __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Stéphane DRAY -- Département des Sciences Biologiques Université de Montréal, C.P. 6128, succursale centre-ville Montréal, Québec H3C 3J7, Canada Tel : (514) 343-6111 poste 1233 Fax : (514) 343-2293 E-mail : [EMAIL PROTECTED] -- Web http://www.steph280.freesurf.fr/ __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] adjusting the map of France to 1830
I'm doing some analyses of historical data from France in 1830 on 'moral statistics' that I'd like to show on a map. I've done most of my analyses in SAS, but a few things would work better in R. To do this, I have to adjust the modern map, library(maps) map('france') to adjust for changes in departments (86 in 1830, to 97 now). I've read the documentation for the maps and maptools package, but there seems to be no functions to allow this, and I can't find information on the exact structure of map datasets, but I understand them to be delimited lists of polygon coordinates. In SAS, all maps have (one or more) ID variables representing the geographical region, and there is also a proc gremove that can remove internal boundaries inside the polygons for regions with the same ID. Is there some way I can do this in R? Here's what I did in SAS: *-- Fix the map of France to conform to Guerry: - adjust the 97 current departments to correspond to the 86 in 1830 - delete those not part of France then ; data gfrtemp; set maps.france; /* Corse was one dept - merge these to one area, new ID */ if id in (201, 202)then dept=200; /* Seine et Oise (78) was cut into Essonne (91), Val d'Oise (95) and Yvelines (78) */ else if id in (91, 95)then dept=78; /* Seine (75) now split into Hauts-de-Seine (92), Seine-Saint-Denis (93) et Val-de-Marne (94)*/ else if id in (92, 93, 94)then dept=75; /* departments not part of France in 1830 */ else if id in ( 6, /* Alpes-Maritimes */ 73,74, /* Savoie, Haute-Savoie */ 90)/* Territore-de-Belfort */ then delete; else dept=id; run; *-- remove internal boundaries based on merged DEPT; proc sort data=gfrtemp; by dept; proc gremove data=gfrtemp out=gfrance; by dept; id id; run; -- Michael Friendly Email: [EMAIL PROTECTED] Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Streethttp://www.math.yorku.ca/SCS/friendly.html Toronto, ONT M3J 1P3 CANADA __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html