trelliscopejs
trelliscopejs copied to clipboard
Error with facet_trelliscope() while facet_wrap() works perfectly well
Good morning
I'm having quite a problem : I created a function aiming to create an HTML file that contains several graphs (representing a temporal evolution)
When a use the facet_wrap() function, I get a pretty interesting result, which is :
(Since I'm manipulating confidential data, I'm only showing a screenshot of the result, with no legends) I then wanted to navigate between the plots, I found that facet_trelliscope() could do so, just by replacing the facet_wrap() function by this one, which I did, but the result is not what I expected :
All the plots have been superimposed..
I tried to run the code outside my function, and I get this error message
using data from the first layer Error in print.facet_trelliscope(x) : all facet_trelliscope facet columns must be found in the data being used
(Note that when I run my function containing the code, I do not get any error message)
The code I'm using to create my plot is the following :
G = ggplot(data = Final_Tab) + geom_col(aes(x = KO, y = percentage, fill = phylum), position = "stack") + facet_trelliscope(~Patient) + labs(y = "Abundance (%)", title = "Plot1") gg <- ggplotly(G) %>% layout(width = 1200, height = 650) htmlwidgets::saveWidget(widget = gg, file = paste(patient, "ISSUE"), selfcontained = FALSE)
The problem may be coming from the data I'm manipulating (It would then be more complicated to solve), but I don't think so since the facet_wrap() function works..
I would be grateful if you had any idea on how to solve this.
Thanks
TukDwal
You can't convert a ggplot object that includes facet_trelliscope()
to plotly in this way. Instead of:
G = ggplot(data = Final_Tab) +
geom_col(aes(x = KO, y = percentage, fill = phylum), position = "stack") +
facet_trelliscope(~Patient) +
labs(y = "Abundance (%)", title = "Plot1")
gg <- ggplotly(G) %>% layout(width = 1200, height = 650)
Instead try this:
G = ggplot(data = Final_Tab) +
geom_col(aes(x = KO, y = percentage, fill = phylum), position = "stack") +
facet_trelliscope(~Patient, width = 1200, height = 650, as_plotly = TRUE) +
labs(y = "Abundance (%)", title = "Plot1")
Thank you for your answer
I'm unfortunately still having the same error message :
using data from the first layer Error in print.facet_trelliscope(x) : all facet_trelliscope facet columns must be found in the data being used
Since I do not really understand that message, I'm having a hard time finding what is wrong..
Besides, using as_plotly = TRUE seems to have done nothing, the class of my resulting item is still
"facet_trelliscope" "gg" "ggplot"
Interesting. I'm afraid I don't have any other ideas without a reprex. Is there a way you can replicate the error with a fake dataset?
As for as_plotly
, that does not change the class of the resulting object, but just ensures that each panel gets converted into a plotly figure when it is plotted.
Ok so I came up with an artificial example that raises the same problem :
library(trelliscopejs)
library(ggplot2)
library(dplyr)
KO = c("A","A","B","D","B","A","D","C","C","B")
specie = c("a","a","b","a","e","g","t","d","g","h")
percentage = c(50, 33, 27, 12, 22, 12, 45, 67, 0, 0)
Patient = c("P1","P1","P1","P2","P2","P2","P2","P3","P3","P3")
df = cbind(KO, specie, percentage, Patient) %>% as.data.frame()
df$specie = as.character(df$specie)
df$percentage = as.numeric(as.character(df$percentage))
First create an artificial datafram that has the same structure as the one I'm manipulating.
Then I try to plot using first facet_wrap() :
G <- ggplot(data = df) + geom_col(aes(x = KO, y = percentage, fill = specie), position = "stack") + facet_wrap(~Patient) + labs(y = "Abundance (%)", title = "Specie abudance") ggplotly(G)
Which displays the following dynamic plot : (just a screenshot here)
But when I simply replace the function with facet_trelliscope, as you suggested, I get an error :
ggplot(data = df) + geom_col(aes(x = KO, y = percentage, fill = specie), position = "stack") + facet_trelliscope(~Patient, nrow = 1, ncol = 1, as_plotly = TRUE) + labs(y = "Abundance (%)", title = "Specie abudance")
Error in print.facet_trelliscope(x) : all facet_trelliscope facet columns must be found in the data being used
(Since it's a reproductible code, I did not use reprex, which I'm not really familiar with)
Thanks for the example. This code works for me, which makes me wonder if there is a version issue. Please post the results of sessionInfo()
.
Strange.. Here is the result I get from sessionInfo()
> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.4
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] fr_FR.UTF-8/fr_FR.UTF-8/fr_FR.UTF-8/C/fr_FR.UTF-8/fr_FR.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] trelliscopejs_0.1.11 ggplot2_2.2.1.9000
loaded via a namespace (and not attached):
[1] Rcpp_0.12.16 knitr_1.20 bindr_0.1.1 magrittr_1.5
[5] progress_1.1.2 munsell_0.4.3 colorspace_1.3-2 R6_2.2.2
[9] rlang_0.2.0.9001 plyr_1.8.4 dplyr_0.7.4 tools_3.4.4
[13] webshot_0.5.0 grid_3.4.4 gtable_0.2.0 withr_2.1.2
[17] htmltools_0.3.6 yaml_2.1.18 lazyeval_0.2.1 assertthat_0.2.0
[21] digest_0.6.15 tibble_1.4.2 bindrcpp_0.2.2 tidyr_0.8.0
[25] purrr_0.2.4 base64enc_0.1-3 DistributionUtils_0.5-1 glue_1.2.0
[29] compiler_3.4.4 pillar_1.2.1 scales_0.5.0.9000 prettyunits_1.0.2
[33] jsonlite_1.5 pkgconfig_2.0.1
It looks like you are using the development version of ggplot2. Can you try it with ggplot2 from CRAN?
I reinstalled the package ggplot2, and now it seems to work! I thought I was already using the current version of ggplot2, seems like it was not the case. Thank you so much for your time and your advices!
@hafen the dev version of ggplot2 is gonna be submitted to CRAN in a couple weeks. Looks like your relying on a lot of internals in https://github.com/hafen/trelliscopejs/blob/master/R/facet_trelliscope.R that have likely changed due to the new tidy evaluation support https://github.com/tidyverse/ggplot2/blob/master/NEWS.md#tidy-evaluation
I have updated the internals so it should be compatible now with the latest ggplot2 changes. @TukDwal can you reinstall and see if this fixes your issue?
Hi! I had overcame the problem by installing the version of ggplot2 which was on CRAN. However the problem is back, I believe since the dev version has been submitted to CRAN as @cpsievert mentionned. I reproduced the exact same example I mentionned here a few months ago, and I get the same problem.. I restored an older version of ggplot2 for now.
What version of trelliscopejs are you using? This has been fixed in 0.1.12.