Rolf Turner
2019-Nov-16 23:11 UTC
[R] Can't get facet_grid_paginate() from ggforce to work.
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
--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: testData.txt
URL:
<https://stat.ethz.ch/pipermail/r-help/attachments/20191117/8f04e41f/attachment.txt>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.pdf
Type: application/pdf
Size: 12321 bytes
Desc: not available
URL:
<https://stat.ethz.ch/pipermail/r-help/attachments/20191117/8f04e41f/attachment.pdf>
Rui Barradas
2019-Nov-17 13:07 UTC
[R] Can't get facet_grid_paginate() from ggforce to work.
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 at 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.
>
Rui Barradas
2019-Nov-17 13:12 UTC
[R] Can't get facet_grid_paginate() from ggforce to work.
Hello,
Sorry, copy&paste did a poor job. The right code now.
library(ggforce)
X <- dget("testData.txt")
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]])
Hope this helps,
Rui Barradas
?s 13:07 de 17/11/19, Rui Barradas escreveu:> 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 at 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 at 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.