[R] Can't get facet_grid_paginate() from ggforce to work.
Rui Barradas
ru|pb@rr@d@@ @end|ng |rom @@po@pt
Sun Nov 17 14:07:12 CET 2019
Hello,
I don't know why but use an explicit nrow = nrows with 'nrows' defined as
nrows <- length(levels(X$Species))
It seems to work (remove the device pdf() code if it's more annoying
than useful):
nrows <- length(levels(X$Species))
ncols <- length(levels(X$LifeStage))
npages <- length(levels(X$degC))
plotObj <- vector("list", npages)
pdf(file = 'Rhelp_test.pdf')
for(page in 1:npages) {nrows <- length(levels(X$Species))
ncols <- length(levels(X$LifeStage))
npages <- length(levels(X$degC))
plotObj <- vector("list", npages)
pdf(file = 'Rhelp_test.pdf')
for(page in 1:npages) {
plotObj[[page]] <- ggplot(X) +
geom_point(aes(y = Sfrac , x = x)) +
facet_grid_paginate(facets = Species ~ LifeStage:degC,
page = page,
nrow = nrows, ncol = ncols)+
ylab("Success fraction") +
theme_bw()
print(ggplot(X) +
geom_point(aes(y = Sfrac , x = x)) +
facet_grid_paginate(facets = Species ~ LifeStage:degC,
page = page,
nrow = nrows, ncol = ncols)+
ylab("Success fraction") +
theme_bw()
)
}
dev.off()
print(plotObj[[1]])
print(plotObj[[2]])
plotObj[[page]] <- ggplot(X) +
geom_point(aes(y = Sfrac , x = x)) +
facet_grid_paginate(facets = Species ~ LifeStage:degC,
page = page,
nrow = nrows, ncol = ncols)+
ylab("Success fraction") +
theme_bw()
print(ggplot(X) +
geom_point(aes(y = Sfrac , x = x)) +
facet_grid_paginate(facets = Species ~ LifeStage:degC,
page = page,
nrow = nrows, ncol = ncols)+
ylab("Success fraction") +
theme_bw()
)
}
dev.off()
print(plotObj[[1]])
print(plotObj[[2]])
Hope this helps,
Rui Barradas
Às 23:11 de 16/11/19, Rolf Turner escreveu:
>
> Clearly there's something that I'm not understanding, but
> facet_grid_paginate() seems to be ignoring the "ncol" argument.
>
> Here's a reprex:
>
> library(ggforce)
> X <- dget("testData.txt")
> ncols <- length(levels(X$LifeStage))
> npages <- length(levels(X$degC))
> plotObj <- vector("list",npages)
> for(page in 1:npages) {
> plotObj[[page]] <- ggplot(X) +
> geom_point(aes(y = Sfrac , x = x)) +
> facet_grid_paginate(facets=Species~LifeStage:degC,
> page=page,ncol=ncols)+
> ylab("Success fraction") +
> theme_bw()
> }
>
> The data set "testData.txt" is attached.
>
> You will see if you "print" plotObj[[1]] that the plot has 8 columns,
> not 4 (4 being the value of "ncols").
>
> The first and second pages seem to be identical; facet_grid_paginate()
> has put everything on one page, and then repeated that page.
>
> I must be doing something utterly stupid, but I can't see what it is.
>
> The example given in the help for ggforce, using the diamonds data,
> looks to me just like my example, except that it works and my example
> doesn't! What am I missing?
>
> What I'm after is something like the plot in the attached pdf file
> test.pdf (which I managed to produce using lattice).
>
> Can anyone point me in the right direction?
>
> Thanks.
>
> cheers,
>
> Rolf Turner
>
>
> ______________________________________________
> R-help using 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.
>
More information about the R-help
mailing list