[R-sig-Geo] layout and plot.stars
edzer@pebe@m@ @end|ng |rom un|-muen@ter@de
Tue Mar 15 16:02:07 CET 2022
In addition to what Roger wrote, you can use e.g.
s = st_as_stars(L7_ETMs)
plot(s[,,,1], key.pos = NULL, reset = FALSE)
plot(s[,,,1], key.pos = NULL, reset = FALSE, main = NULL)
to fill the sub-plots of layout() incrementally. Note the key.pos and
reset arguments to plot.stars(): they make sure plot.stars doesn't mess
with the layout settings.
On 15/03/2022 11:45, Patrick Giraudoux wrote:
> Great ! Thanks Roger. On this basis, I have a way to explore the issue
> now. Will give a feed-back on the list once done.
> Le 15/03/2022 à 11:27, Roger Bivand a écrit :
>> On Tue, 15 Mar 2022, Patrick Giraudoux wrote:
>>> I have a trouble with the combination of layout and plot.stars. e.g.
>>> nf <- layout(matrix(c(1,2),2,1,byrow = TRUE), c(3,3), c(3,1), TRUE)
>> You have already noticed that sf and stars, like raster and terra,
>> modify the assumptions of base plot methods, as
>> graphics::filled.contour(), unless some ordering and argument
>> conditions are met, crucially the non-base reset= argument. I do not
>> think that you can use layout() at all.
>> nc <- st_read(system.file("gpkg/nc.gpkg", package="sf"))
>> bir74_rast <- st_rasterize(nc["BIR74"])
>> plot(bir74_rast, reset=FALSE)
>> plot(st_geometry(nc),border="grey90", add=TRUE)
>> g <- grid.grab()
>> gv <- grid.grab()
>> gridExtra::grid.arrange(g, gv, ncol=2)
>> Grabbing the base graphics device state lets you use
>> gridExtra::grid.arrange() to place multiple graphics objects; here I
>> haven't tried to constrain aspect or relative sizes. I don't think
>> that the plot methods in sf and stars play well with layout, because
>> they use it themselves internally.
>> Hope this helps,
>>> I expect that the first two plots display in region #1, the second
>>> added to the first, and the third plot in region #2. However, this is
>>> not what happens: actually, the third plot displays in region 1
>>> erasing the others. I understand that plot.stars when not "added"
>>> does not respect the layout definition (and displays its own
>>> regions), and that my problem comes from the way plot.stars deals
>>> with that.
>>> Has anyone an idea about a workaround ?
>>> R-sig-Geo mailing list
>>> R-sig-Geo using r-project.org
> [[alternative HTML version deleted]]
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
Institute for Geoinformatics
Heisenbergstrasse 2, 48151 Muenster, Germany
Phone: +49 251 8333081
More information about the R-sig-Geo