Hello,
I have a SpatialPolygonsDataFrame. I would like to do a trellis plot on one of the attributes, so that in the panel for a given attribute value, only those polygons with that value are plotted. So, each panel has different polygons plotted in it. I can't figure out how to do this. In the toy example below, I would like to create a trellis plot with one panel showing the polygons with id = 1, and another panel showing the polygons with id = 2. My goal beyond this toy problem is to do the same thing with stplot, where panels correspond to times and each time has a different set of polygons plotted. Will that be possible? In all the examples I can find of using stplot for a spacetime grid with the spatial objects being polygons, the polygons are the same across time. # based on example in help("SpatialPolygonsDataFrameclass") Sr1 = Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2))) Sr2 = Polygon(cbind(c(5,4,2,5),c(2,3,2,2))) Sr3 = Polygon(cbind(c(4,4,5,10,4),c(5,3,2,5,5))) Sr4 = Polygon(cbind(c(5,6,6,5,5),c(4,4,3,3,4)), hole = TRUE) Srs1 = Polygons(list(Sr1), "s1") Srs2 = Polygons(list(Sr2), "s2") Srs3 = Polygons(list(Sr3, Sr4), "s3/4") SpP = SpatialPolygons(list(Srs1,Srs2,Srs3), 1:3) grd < GridTopology(c(1,1), c(1,1), c(10,10)) polys < as(grd, "SpatialPolygons") centroids < coordinates(polys) x < centroids[,1] y < centroids[,2] z < 1.4 + 0.1*x + 0.2*y + 0.002*x*x id = factor(sample(c(1,2), size=length(polys), replace=T)) tmp < SpatialPolygonsDataFrame(polys, data=data.frame(x=x, y=y, z=z, id=id, row.names=row.names(polys))) plot(tmp) # plots all the square polygons (n = 10*10) spplot(tmp) # plots values of x, y, z, id in separate panels, each with 100 polys spplot(tmp, zcol=z) # error message about duplication of factor level spplot(tmp ~ id, zcol=z, data=tmp) # won't take formula Thank you, ScottWaichler Pacific Northwest National Laboratory scott.waichler _at_ pnnl.gov _______________________________________________ RsigGeo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/rsiggeo 
Administrator

Scott,
Without having tried your code, how similar is this to these packages: https://cran.rproject.org/package=micromap https://cran.rproject.org/package=micromapST and their JSS papers: https://www.jstatsoft.org/index.php/jss/article/view/v063i02 https://www.jstatsoft.org/index.php/jss/article/view/v063i03 Roger On Wed, 23 May 2018, Waichler, Scott R wrote: > Hello, > > I have a SpatialPolygonsDataFrame. I would like to do a trellis plot on one of the attributes, so that in the panel for a given attribute value, only those polygons with that value are plotted. So, each panel has different polygons plotted in it. I can't figure out how to do this. In the toy example below, I would like to create a trellis plot with one panel showing the polygons with id = 1, and another panel showing the polygons with id = 2. > > My goal beyond this toy problem is to do the same thing with stplot, where panels correspond to times and each time has a different set of polygons plotted. Will that be possible? In all the examples I can find of using stplot for a spacetime grid with the spatial objects being polygons, the polygons are the same across time. > > # based on example in help("SpatialPolygonsDataFrameclass") > Sr1 = Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2))) > Sr2 = Polygon(cbind(c(5,4,2,5),c(2,3,2,2))) > Sr3 = Polygon(cbind(c(4,4,5,10,4),c(5,3,2,5,5))) > Sr4 = Polygon(cbind(c(5,6,6,5,5),c(4,4,3,3,4)), hole = TRUE) > Srs1 = Polygons(list(Sr1), "s1") > Srs2 = Polygons(list(Sr2), "s2") > Srs3 = Polygons(list(Sr3, Sr4), "s3/4") > SpP = SpatialPolygons(list(Srs1,Srs2,Srs3), 1:3) > grd < GridTopology(c(1,1), c(1,1), c(10,10)) > polys < as(grd, "SpatialPolygons") > centroids < coordinates(polys) > x < centroids[,1] > y < centroids[,2] > z < 1.4 + 0.1*x + 0.2*y + 0.002*x*x > id = factor(sample(c(1,2), size=length(polys), replace=T)) > tmp < SpatialPolygonsDataFrame(polys, > data=data.frame(x=x, y=y, z=z, id=id, row.names=row.names(polys))) > plot(tmp) # plots all the square polygons (n = 10*10) > spplot(tmp) # plots values of x, y, z, id in separate panels, each with 100 polys > spplot(tmp, zcol=z) # error message about duplication of factor level > spplot(tmp ~ id, zcol=z, data=tmp) # won't take formula > > Thank you, > ScottWaichler > Pacific Northwest National Laboratory > scott.waichler _at_ pnnl.gov > > _______________________________________________ > RsigGeo mailing list > [hidden email] > https://stat.ethz.ch/mailman/listinfo/rsiggeo >  Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N5045 Bergen, Norway. voice: +47 55 95 93 55; email: [hidden email] http://orcid.org/0000000323926140 https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en _______________________________________________ RsigGeo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/rsiggeo
Roger Bivand
Department of Economics Norwegian School of Economics Helleveien 30 N5045 Bergen, Norway 
Roger,
> Without having tried your code, how similar is this to these packages: > > https://cran.rproject.org/package=micromap > https://cran.rproject.org/package=micromapST Thanks for responding. I looked at the micromap vignettes but it seems their focus is being able to provide small maps in one column in figures where the main emphasis is on statistics presented in other columns. In my problem, all I want to show are maps. I haven't been able to do this with a higherlevel function like spplot or stplot. I can imagine doing it with a custom panel function, where lpolygons() is used with input that depends on the panel. In case it helps, I should clarify that the "different polygons" I referred to are polygons with different spatial coordinates; the attribute values are a small number of discrete values. My polygons are representations of contaminant plumes in groundwater. For each year, I have read in a shapefile containing polygons of the contaminant concentration at 2 to 4 levels. I have combined all of these data into a SpatialPolygonsDataFrame, where each row represents a given year and concentration level, and contains one or more polygons. The coordinates are different in each row, but years and concentration level are common across rows. This seems to match the nature of a "long table" format in spacetime, but I haven't been able to work it out in that package, hence I'm stepping back and trying to get the basics working with spplot. Thanks, Scott > > Hello, > > > > I have a SpatialPolygonsDataFrame. I would like to do a trellis plot on one > of the attributes, so that in the panel for a given attribute value, only those > polygons with that value are plotted. So, each panel has different polygons > plotted in it. I can't figure out how to do this. In the toy example below, I > would like to create a trellis plot with one panel showing the polygons with id > = 1, and another panel showing the polygons with id = 2. > > > > My goal beyond this toy problem is to do the same thing with stplot, where > panels correspond to times and each time has a different set of polygons > plotted. Will that be possible? In all the examples I can find of using stplot > for a spacetime grid with the spatial objects being polygons, the polygons > are the same across time. > > > > # based on example in help("SpatialPolygonsDataFrameclass") > > Sr1 = Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2))) > > Sr2 = Polygon(cbind(c(5,4,2,5),c(2,3,2,2))) > > Sr3 = Polygon(cbind(c(4,4,5,10,4),c(5,3,2,5,5))) > > Sr4 = Polygon(cbind(c(5,6,6,5,5),c(4,4,3,3,4)), hole = TRUE) > > Srs1 = Polygons(list(Sr1), "s1") > > Srs2 = Polygons(list(Sr2), "s2") > > Srs3 = Polygons(list(Sr3, Sr4), "s3/4") SpP = > > SpatialPolygons(list(Srs1,Srs2,Srs3), 1:3) grd < GridTopology(c(1,1), > > c(1,1), c(10,10)) polys < as(grd, "SpatialPolygons") centroids < > > coordinates(polys) x < centroids[,1] y < centroids[,2] z < 1.4 + > > 0.1*x + 0.2*y + 0.002*x*x id = factor(sample(c(1,2), > > size=length(polys), replace=T)) tmp < SpatialPolygonsDataFrame(polys, > > data=data.frame(x=x, y=y, z=z, id=id, > > row.names=row.names(polys))) > > plot(tmp) # plots all the square polygons (n = 10*10) > > spplot(tmp) # plots values of x, y, z, id in separate panels, each > > with 100 polys spplot(tmp, zcol=z) # error message about duplication > > of factor level spplot(tmp ~ id, zcol=z, data=tmp) # won't take > > formula > > > > Thank you, > > ScottWaichler > > Pacific Northwest National Laboratory > > scott.waichler _at_ pnnl.gov > > > > _______________________________________________ > > RsigGeo mailing list > > [hidden email] > > https://stat.ethz.ch/mailman/listinfo/rsiggeo > > > >  > Roger Bivand > Department of Economics, Norwegian School of Economics, Helleveien 30, N > 5045 Bergen, Norway. > voice: +47 55 95 93 55; email: [hidden email] > http://orcid.org/0000000323926140 > https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en _______________________________________________ RsigGeo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/rsiggeo 
Dear Scott,
use spplot(tmp, zcol="z") instead of spplot(tmp, zcol=z) to display the column "z". Use spplot(tmp[tmp$id == 1, ], zcol = "z") to display only those grids that has id 1. And to display two panels: tmp$z1 < tmp$z2 < tmp$z tmp$z1[tmp$id == 1] < NA tmp$z2[tmp$id == 2] < NA spplot(tmp, zcol=c("z1", "z2")) HTH, Ákos BedeFazekas Hungarian Academy of Sciences 2018.05.23. 21:50 keltezéssel, Waichler, Scott R írta: > Roger, > >> Without having tried your code, how similar is this to these packages: >> >> https://cran.rproject.org/package=micromap >> https://cran.rproject.org/package=micromapST > Thanks for responding. I looked at the micromap vignettes but it seems their focus is being able to provide small maps in one column in figures where the main emphasis is on statistics presented in other columns. In my problem, all I want to show are maps. I haven't been able to do this with a higherlevel function like spplot or stplot. I can imagine doing it with a custom panel function, where lpolygons() is used with input that depends on the panel. > > In case it helps, I should clarify that the "different polygons" I referred to are polygons with different spatial coordinates; the attribute values are a small number of discrete values. My polygons are representations of contaminant plumes in groundwater. For each year, I have read in a shapefile containing polygons of the contaminant concentration at 2 to 4 levels. I have combined all of these data into a SpatialPolygonsDataFrame, where each row represents a given year and concentration level, and contains one or more polygons. The coordinates are different in each row, but years and concentration level are common across rows. This seems to match the nature of a "long table" format in spacetime, but I haven't been able to work it out in that package, hence I'm stepping back and trying to get the basics working with spplot. > > Thanks, > Scott > >>> Hello, >>> >>> I have a SpatialPolygonsDataFrame. I would like to do a trellis plot on one >> of the attributes, so that in the panel for a given attribute value, only those >> polygons with that value are plotted. So, each panel has different polygons >> plotted in it. I can't figure out how to do this. In the toy example below, I >> would like to create a trellis plot with one panel showing the polygons with id >> = 1, and another panel showing the polygons with id = 2. >>> My goal beyond this toy problem is to do the same thing with stplot, where >> panels correspond to times and each time has a different set of polygons >> plotted. Will that be possible? In all the examples I can find of using stplot >> for a spacetime grid with the spatial objects being polygons, the polygons >> are the same across time. >>> # based on example in help("SpatialPolygonsDataFrameclass") >>> Sr1 = Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2))) >>> Sr2 = Polygon(cbind(c(5,4,2,5),c(2,3,2,2))) >>> Sr3 = Polygon(cbind(c(4,4,5,10,4),c(5,3,2,5,5))) >>> Sr4 = Polygon(cbind(c(5,6,6,5,5),c(4,4,3,3,4)), hole = TRUE) >>> Srs1 = Polygons(list(Sr1), "s1") >>> Srs2 = Polygons(list(Sr2), "s2") >>> Srs3 = Polygons(list(Sr3, Sr4), "s3/4") SpP = >>> SpatialPolygons(list(Srs1,Srs2,Srs3), 1:3) grd < GridTopology(c(1,1), >>> c(1,1), c(10,10)) polys < as(grd, "SpatialPolygons") centroids < >>> coordinates(polys) x < centroids[,1] y < centroids[,2] z < 1.4 + >>> 0.1*x + 0.2*y + 0.002*x*x id = factor(sample(c(1,2), >>> size=length(polys), replace=T)) tmp < SpatialPolygonsDataFrame(polys, >>> data=data.frame(x=x, y=y, z=z, id=id, >>> row.names=row.names(polys))) >>> plot(tmp) # plots all the square polygons (n = 10*10) >>> spplot(tmp) # plots values of x, y, z, id in separate panels, each >>> with 100 polys spplot(tmp, zcol=z) # error message about duplication >>> of factor level spplot(tmp ~ id, zcol=z, data=tmp) # won't take >>> formula >>> >>> Thank you, >>> ScottWaichler >>> Pacific Northwest National Laboratory >>> scott.waichler _at_ pnnl.gov >>> >>> _______________________________________________ >>> RsigGeo mailing list >>> [hidden email] >>> https://stat.ethz.ch/mailman/listinfo/rsiggeo >>> >>  >> Roger Bivand >> Department of Economics, Norwegian School of Economics, Helleveien 30, N >> 5045 Bergen, Norway. >> voice: +47 55 95 93 55; email: [hidden email] >> http://orcid.org/0000000323926140 >> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en > _______________________________________________ > RsigGeo mailing list > [hidden email] > https://stat.ethz.ch/mailman/listinfo/rsiggeo > _______________________________________________ RsigGeo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/rsiggeo 
In reply to this post by Waichler, Scott R2
On Thu, May 24, 2018 at 6:00 AM, <[hidden email]> wrote:
> > Message: 1 > Date: Wed, 23 May 2018 18:39:07 +0000 > From: "Waichler, Scott R" <[hidden email]> > To: "[hidden email]" <[hidden email]> > Subject: [RsigGeo] how to plot different rows of a > SpatialPolygonsDataFrame in trellis panels > > Hello, > > I have a SpatialPolygonsDataFrame. I would like to do a trellis plot on > one of the attributes, so that in the panel for a given attribute value, > only those polygons with that value are plotted. So, each panel has > different polygons plotted in it. I can't figure out how to do this. In > the toy example below, I would like to create a trellis plot with one panel > showing the polygons with id = 1, and another panel showing the polygons > with id = 2. > > My goal beyond this toy problem is to do the same thing with stplot, where > panels correspond to times and each time has a different set of polygons > plotted. Will that be possible? In all the examples I can find of using > stplot for a spacetime grid with the spatial objects being polygons, the > polygons are the same across time. > > # based on example in help("SpatialPolygonsDataFrameclass") > Sr1 = Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2))) > Sr2 = Polygon(cbind(c(5,4,2,5),c(2,3,2,2))) > Sr3 = Polygon(cbind(c(4,4,5,10,4),c(5,3,2,5,5))) > Sr4 = Polygon(cbind(c(5,6,6,5,5),c(4,4,3,3,4)), hole = TRUE) > Srs1 = Polygons(list(Sr1), "s1") > Srs2 = Polygons(list(Sr2), "s2") > Srs3 = Polygons(list(Sr3, Sr4), "s3/4") > SpP = SpatialPolygons(list(Srs1,Srs2,Srs3), 1:3) > grd < GridTopology(c(1,1), c(1,1), c(10,10)) > polys < as(grd, "SpatialPolygons") > centroids < coordinates(polys) > x < centroids[,1] > y < centroids[,2] > z < 1.4 + 0.1*x + 0.2*y + 0.002*x*x > id = factor(sample(c(1,2), size=length(polys), replace=T)) > tmp < SpatialPolygonsDataFrame(polys, > data=data.frame(x=x, y=y, z=z, id=id, row.names=row.names(polys))) > plot(tmp) # plots all the square polygons (n = 10*10) > spplot(tmp) # plots values of x, y, z, id in separate panels, each with > 100 polys > spplot(tmp, zcol=z) # error message about duplication of factor level > spplot(tmp ~ id, zcol=z, data=tmp) # won't take formula > You can do the facetting with ggplot2::geom_sf (in the dev version of ggplot2) though I don't think it will use different coordinate ranges for different facets: devtools::install_github('tidyverse/ggplot2') library(sf) library(ggplot2) tmp2 = st_as_sf(tmp) ggplot(tmp2) + geom_sf(aes(fill=z)) + facet_wrap(~id) A couple of suggestions here, using tmap or ggspatial, that look promising: https://stackoverflow.com/questions/47678480/mappingdifferentstateswithgeomsfusingfacetwrapandscalesfree Kent Johnson > Thank you, > ScottWaichler > Pacific Northwest National Laboratory > scott.waichler _at_ pnnl.gov > [[alternative HTML version deleted]] _______________________________________________ RsigGeo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/rsiggeo 
Kent,
Thank you for your response to my problem. Unfortunately, I can't use sf because it has system dependencies I can't meet. I am using RHEL 6, and am uptodate with it for gdal, geos, and proj (versions 1.7.3, 3.3.2, 4.7.0 respectively), but the R package sf requires later versions for all of these. The vignettes for sf make it sound very useful, but alas it seems to be out of reach for me at present. I am surprised a package that is being positioned for widespread adoption has such stringent requirements. Best, Scott Waichler Pacific Northwest National Laboratory Richland, Washington, USA > Original Message > From: Kent Johnson [mailto:[hidden email]] > Sent: Thursday, May 24, 2018 6:05 AM > To: [hidden email]; Waichler, Scott R <[hidden email]> > Subject: Re: how to plot different rows of a SpatialPolygonsDataFrame in > trellis panels > > On Thu, May 24, 2018 at 6:00 AM, <[hidden email]> wrote: > > Message: 1 > Date: Wed, 23 May 2018 18:39:07 +0000 > From: "Waichler, Scott R" <[hidden email]> > To: "[hidden email]" <[hidden email]> > Subject: [RsigGeo] how to plot different rows of a > SpatialPolygonsDataFrame in trellis panels > > Hello, > > I have a SpatialPolygonsDataFrame. I would like to do a trellis plot on one of > the attributes, so that in the panel for a given attribute value, only those > polygons with that value are plotted. So, each panel has different polygons > plotted in it. I can't figure out how to do this. In the toy example below, I > would like to create a trellis plot with one panel showing the polygons with id > = 1, and another panel showing the polygons with id = 2. > > My goal beyond this toy problem is to do the same thing with stplot, where > panels correspond to times and each time has a different set of polygons > plotted. Will that be possible? In all the examples I can find of using stplot > for a spacetime grid with the spatial objects being polygons, the polygons > are the same across time. > > # based on example in help("SpatialPolygonsDataFrameclass") > Sr1 = Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2))) > Sr2 = Polygon(cbind(c(5,4,2,5),c(2,3,2,2))) > Sr3 = Polygon(cbind(c(4,4,5,10,4),c(5,3,2,5,5))) > Sr4 = Polygon(cbind(c(5,6,6,5,5),c(4,4,3,3,4)), hole = TRUE) > Srs1 = Polygons(list(Sr1), "s1") > Srs2 = Polygons(list(Sr2), "s2") > Srs3 = Polygons(list(Sr3, Sr4), "s3/4") > SpP = SpatialPolygons(list(Srs1,Srs2,Srs3), 1:3) > grd < GridTopology(c(1,1), c(1,1), c(10,10)) > polys < as(grd, "SpatialPolygons") > centroids < coordinates(polys) > x < centroids[,1] > y < centroids[,2] > z < 1.4 + 0.1*x + 0.2*y + 0.002*x*x > id = factor(sample(c(1,2), size=length(polys), replace=T)) > tmp < SpatialPolygonsDataFrame(polys, > data=data.frame(x=x, y=y, z=z, id=id, row.names=row.names(polys))) > plot(tmp) # plots all the square polygons (n = 10*10) > spplot(tmp) # plots values of x, y, z, id in separate panels, each with 100 > polys > spplot(tmp, zcol=z) # error message about duplication of factor level > spplot(tmp ~ id, zcol=z, data=tmp) # won't take formula > > You can do the facetting with ggplot2::geom_sf (in the dev version of > ggplot2) though I don't think it will use different coordinate ranges for > different facets: > > devtools::install_github('tidyverse/ggplot2') > library(sf) > library(ggplot2) > tmp2 = st_as_sf(tmp) > > ggplot(tmp2) + geom_sf(aes(fill=z)) + facet_wrap(~id) > > A couple of suggestions here, using tmap or ggspatial, that look promising: > https://stackoverflow.com/questions/47678480/mappingdifferentstates > withgeomsfusingfacetwrapandscalesfree > > Kent Johnson > > > Thank you, > ScottWaichler > Pacific Northwest National Laboratory > scott.waichler _at_ pnnl.gov RsigGeo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/rsiggeo 
On 06/01/2018 05:38 AM, Waichler, Scott R wrote: > Kent, > > Thank you for your response to my problem. Unfortunately, I can't use sf because it has system dependencies I can't meet. I am using RHEL 6, and am uptodate with it for gdal, geos, and proj (versions 1.7.3, 3.3.2, 4.7.0 respectively), but the R package sf requires later versions for all of these. The vignettes for sf make it sound very useful, but alas it seems to be out of reach for me at present. I am surprised a package that is being positioned for widespread adoption has such stringent requirements. According to https://download.osgeo.org/gdal/old_releases/ the gdal version you are running is from 2010. You may have followed how gdal has improved since 2010, and how it has continuously adapted to the dynamics of the geospatial software ecosystem, as well as to the development of new geospatial standards. I made a deliberate choice to let sf users benefit from these improvements by picking gdal 2.0.1 from 2015 as a minimum requirement, rather than keep them in the stone ages. Keeping sf, rgdal and rgeos to work with new releases of gdal, geos and proj takes a considerable amount of our time not only for Roger and me, but also for the CRAN maintainers. I hope this takes away some of your surprise. > > Best, > Scott Waichler > Pacific Northwest National Laboratory > Richland, Washington, USA > >> Original Message >> From: Kent Johnson [mailto:[hidden email]] >> Sent: Thursday, May 24, 2018 6:05 AM >> To: [hidden email]; Waichler, Scott R <[hidden email]> >> Subject: Re: how to plot different rows of a SpatialPolygonsDataFrame in >> trellis panels >> >> On Thu, May 24, 2018 at 6:00 AM, <[hidden email]> wrote: >> >> Message: 1 >> Date: Wed, 23 May 2018 18:39:07 +0000 >> From: "Waichler, Scott R" <[hidden email]> >> To: "[hidden email]" <[hidden email]> >> Subject: [RsigGeo] how to plot different rows of a >> SpatialPolygonsDataFrame in trellis panels >> >> Hello, >> >> I have a SpatialPolygonsDataFrame. I would like to do a trellis plot on one of >> the attributes, so that in the panel for a given attribute value, only those >> polygons with that value are plotted. So, each panel has different polygons >> plotted in it. I can't figure out how to do this. In the toy example below, I >> would like to create a trellis plot with one panel showing the polygons with id >> = 1, and another panel showing the polygons with id = 2. >> >> My goal beyond this toy problem is to do the same thing with stplot, where >> panels correspond to times and each time has a different set of polygons >> plotted. Will that be possible? In all the examples I can find of using stplot >> for a spacetime grid with the spatial objects being polygons, the polygons >> are the same across time. >> >> # based on example in help("SpatialPolygonsDataFrameclass") >> Sr1 = Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2))) >> Sr2 = Polygon(cbind(c(5,4,2,5),c(2,3,2,2))) >> Sr3 = Polygon(cbind(c(4,4,5,10,4),c(5,3,2,5,5))) >> Sr4 = Polygon(cbind(c(5,6,6,5,5),c(4,4,3,3,4)), hole = TRUE) >> Srs1 = Polygons(list(Sr1), "s1") >> Srs2 = Polygons(list(Sr2), "s2") >> Srs3 = Polygons(list(Sr3, Sr4), "s3/4") >> SpP = SpatialPolygons(list(Srs1,Srs2,Srs3), 1:3) >> grd < GridTopology(c(1,1), c(1,1), c(10,10)) >> polys < as(grd, "SpatialPolygons") >> centroids < coordinates(polys) >> x < centroids[,1] >> y < centroids[,2] >> z < 1.4 + 0.1*x + 0.2*y + 0.002*x*x >> id = factor(sample(c(1,2), size=length(polys), replace=T)) >> tmp < SpatialPolygonsDataFrame(polys, >> data=data.frame(x=x, y=y, z=z, id=id, row.names=row.names(polys))) >> plot(tmp) # plots all the square polygons (n = 10*10) >> spplot(tmp) # plots values of x, y, z, id in separate panels, each with 100 >> polys >> spplot(tmp, zcol=z) # error message about duplication of factor level >> spplot(tmp ~ id, zcol=z, data=tmp) # won't take formula >> >> You can do the facetting with ggplot2::geom_sf (in the dev version of >> ggplot2) though I don't think it will use different coordinate ranges for >> different facets: >> >> devtools::install_github('tidyverse/ggplot2') >> library(sf) >> library(ggplot2) >> tmp2 = st_as_sf(tmp) >> >> ggplot(tmp2) + geom_sf(aes(fill=z)) + facet_wrap(~id) >> >> A couple of suggestions here, using tmap or ggspatial, that look promising: >> https://stackoverflow.com/questions/47678480/mappingdifferentstates >> withgeomsfusingfacetwrapandscalesfree >> >> Kent Johnson >> >> >> Thank you, >> ScottWaichler >> Pacific Northwest National Laboratory >> scott.waichler _at_ pnnl.gov > _______________________________________________ > RsigGeo mailing list > [hidden email] > https://stat.ethz.ch/mailman/listinfo/rsiggeo >  Edzer Pebesma Institute for Geoinformatics Heisenbergstrasse 2, 48151 Muenster, Germany Phone: +49 251 8333081 _______________________________________________ RsigGeo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/rsiggeo 
Administrator

On Fri, 1 Jun 2018, Edzer Pebesma wrote:
> > > On 06/01/2018 05:38 AM, Waichler, Scott R wrote: >> Kent, >> >> Thank you for your response to my problem. Unfortunately, I can't use >> sf because it has system dependencies I can't meet. I am using RHEL 6, >> and am uptodate with it for gdal, geos, and proj (versions 1.7.3, >> 3.3.2, 4.7.0 respectively), but the R package sf requires later >> versions for all of these. The vignettes for sf make it sound very >> useful, but alas it seems to be out of reach for me at present. I am >> surprised a package that is being positioned for widespread adoption >> has such stringent requirements. > > According to https://download.osgeo.org/gdal/old_releases/ the gdal > version you are running is from 2010. You may have followed how gdal has > improved since 2010, and how it has continuously adapted to the dynamics > of the geospatial software ecosystem, as well as to the development of > new geospatial standards. Edzer mentions, PROJ, GDAL and GEOS have fixed multiple bugs GDAL has introduced new drivers over the succession of releases. The GDAL API changed after 1.11.*, but rgdal does still build with GDAL 1.11.4 and PROJ 4.8.0 (checked recently). From the next (forthcoming) release (1.3.*) of rgdal, these will be the minimum versions permitted. Even CentOS/RHEL 7 need to install a C++11capable compiler to build GDAL 2.3.0  see the thread at: https://stat.ethz.ch/pipermail/rsiggeo/2018May/026591.html As Edzer mentions below, users cannot reasonably expect package authors and maintainers to keep things running in current packages for EOLnear platforms. If you can provide docker images/containers to emulate nearEOL platforms (compilers, external dependencies, etc), you can contribute back to others and protect your workflows by checking systematically that development versions of sf and rgdal/rgeos can still be installed, pass R CMD check, and that updates in R packages don't change your results in other ways than bugfixes would cause. We know that institutional users cannot freely upgrade platforms, but RHEL 6 perhaps indicates critical failure to invest by the institution; we know it happens, but this can't be a priority for package author and maintainer time. Roger > > I made a deliberate choice to let sf users benefit from these > improvements by picking gdal 2.0.1 from 2015 as a minimum requirement, > rather than keep them in the stone ages. > > Keeping sf, rgdal and rgeos to work with new releases of gdal, geos and > proj takes a considerable amount of our time not only for Roger and me, > but also for the CRAN maintainers. I hope this takes away some of your > surprise. > >> >> Best, >> Scott Waichler >> Pacific Northwest National Laboratory >> Richland, Washington, USA >> >>> Original Message >>> From: Kent Johnson [mailto:[hidden email]] >>> Sent: Thursday, May 24, 2018 6:05 AM >>> To: [hidden email]; Waichler, Scott R <[hidden email]> >>> Subject: Re: how to plot different rows of a SpatialPolygonsDataFrame in >>> trellis panels >>> >>> On Thu, May 24, 2018 at 6:00 AM, <[hidden email]> wrote: >>> >>> Message: 1 >>> Date: Wed, 23 May 2018 18:39:07 +0000 >>> From: "Waichler, Scott R" <[hidden email]> >>> To: "[hidden email]" <[hidden email]> >>> Subject: [RsigGeo] how to plot different rows of a >>> SpatialPolygonsDataFrame in trellis panels >>> >>> Hello, >>> >>> I have a SpatialPolygonsDataFrame. I would like to do a trellis plot on one of >>> the attributes, so that in the panel for a given attribute value, only those >>> polygons with that value are plotted. So, each panel has different polygons >>> plotted in it. I can't figure out how to do this. In the toy example below, I >>> would like to create a trellis plot with one panel showing the polygons with id >>> = 1, and another panel showing the polygons with id = 2. >>> >>> My goal beyond this toy problem is to do the same thing with stplot, where >>> panels correspond to times and each time has a different set of polygons >>> plotted. Will that be possible? In all the examples I can find of using stplot >>> for a spacetime grid with the spatial objects being polygons, the polygons >>> are the same across time. >>> >>> # based on example in help("SpatialPolygonsDataFrameclass") >>> Sr1 = Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2))) >>> Sr2 = Polygon(cbind(c(5,4,2,5),c(2,3,2,2))) >>> Sr3 = Polygon(cbind(c(4,4,5,10,4),c(5,3,2,5,5))) >>> Sr4 = Polygon(cbind(c(5,6,6,5,5),c(4,4,3,3,4)), hole = TRUE) >>> Srs1 = Polygons(list(Sr1), "s1") >>> Srs2 = Polygons(list(Sr2), "s2") >>> Srs3 = Polygons(list(Sr3, Sr4), "s3/4") >>> SpP = SpatialPolygons(list(Srs1,Srs2,Srs3), 1:3) >>> grd < GridTopology(c(1,1), c(1,1), c(10,10)) >>> polys < as(grd, "SpatialPolygons") >>> centroids < coordinates(polys) >>> x < centroids[,1] >>> y < centroids[,2] >>> z < 1.4 + 0.1*x + 0.2*y + 0.002*x*x >>> id = factor(sample(c(1,2), size=length(polys), replace=T)) >>> tmp < SpatialPolygonsDataFrame(polys, >>> data=data.frame(x=x, y=y, z=z, id=id, row.names=row.names(polys))) >>> plot(tmp) # plots all the square polygons (n = 10*10) >>> spplot(tmp) # plots values of x, y, z, id in separate panels, each with 100 >>> polys >>> spplot(tmp, zcol=z) # error message about duplication of factor level >>> spplot(tmp ~ id, zcol=z, data=tmp) # won't take formula >>> >>> You can do the facetting with ggplot2::geom_sf (in the dev version of >>> ggplot2) though I don't think it will use different coordinate ranges for >>> different facets: >>> >>> devtools::install_github('tidyverse/ggplot2') >>> library(sf) >>> library(ggplot2) >>> tmp2 = st_as_sf(tmp) >>> >>> ggplot(tmp2) + geom_sf(aes(fill=z)) + facet_wrap(~id) >>> >>> A couple of suggestions here, using tmap or ggspatial, that look promising: >>> https://stackoverflow.com/questions/47678480/mappingdifferentstates >>> withgeomsfusingfacetwrapandscalesfree >>> >>> Kent Johnson >>> >>> >>> Thank you, >>> ScottWaichler >>> Pacific Northwest National Laboratory >>> scott.waichler _at_ pnnl.gov >> _______________________________________________ >> RsigGeo mailing list >> [hidden email] >> https://stat.ethz.ch/mailman/listinfo/rsiggeo >> > > Roger Bivand Department of Economics, Norwegian School of Economics, Helleveien 30, N5045 Bergen, Norway. voice: +47 55 95 93 55; email: [hidden email] http://orcid.org/0000000323926140 https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en _______________________________________________ RsigGeo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/rsiggeo
Roger Bivand
Department of Economics Norwegian School of Economics Helleveien 30 N5045 Bergen, Norway 
Free forum by Nabble  Edit this page 