ggpubr 2 Issues in blog post: "How to create Beautiful plots..."
Hi Kassambara!
In blog post: "How to create beautiful plots in R" https://www.datanovia.com/en/blog/how-to-create-a-beautiful-plots-in-r-with-summary-statistics-labels/
all R code examples work great, 100%, except for 2 issues.
Issue 1) The almost last code example: does not render any plot, Rstudio's Plot Panel is totally empty...
## Create independent panels using the argument free:
ggsummarystats( df, x = "dose", y = "len", ggfunc = ggboxplot, add = c("jitter"), color = "dose", palette = "jco", facet.by = c("supp", "qc"), labeller = "label_both", free.panels = TRUE, ggtheme = theme_bw(), legend = "top" )
Warning message: In stats::qt(alpha/2, .data$n - 1) : NaNs produced
Issue 2)
Build step by step a custom multipanel plot
Create a multipanel box plot using one grouping variable (supp):
# Group the data by supp Apply the function ggsummarystats to each subset df.grouped <- df %>% df_split_by(supp, label_col = "panel", labeller = df_label_both) %>% mutate(plot_list = map( data, ggsummarystats, x = "dose", y = "len", ggfunc = ggbarplot, add = c("jitter", "median_iqr"), facet.by = "panel" ) ) Error in map(data, ggsummarystats, x = "dose", y = "len", ggfunc = ggbarplot, : could not find function "map"
Hmmm. What pkg should be loaded for the function map() ?.
SFd99 ‘ggpubr’ version 0.2.5.999 Ubuntu Linux 18.04 w/ latest versions of Rstudio and R (3.6.3).
issue 1) is not reproducible on my computer. Enlarging the Rstudio viewer panel might help.
for issue 2) make sure you have loaded the required R package as specified in the article:
library(tidyverse)
library(rstatix)
library(ggpubr)
The function map() is from the purrr package include in the tidyverse
Hi Kassambara!. Thanks for your suggestions.
Pkgs loaded (latest versions):
(.packages()) [1] "purrr" "ggpubr"
[3] "rstatix" "janitor"
[5] "magrittr" "reshape2" [7] "tidyr" "ggplot2"
[9] "dplyr" "stats"
[11] "graphics" "grDevices" [13] "utils" "datasets" [15] "methods" "base"
Tried on an LG 17 inch monitor.
Issue# 1:
Message after code executes: "Warning message: In stats::qt(alpha/2, .data$n - 1) : NaNs produced"
Still, no plot is displayed on the (99% maximized) Plot Panel of Rstudio. --------------
Issue# 2: purrr 034 and all req.pkgs loaded.
No error messages! But,same as Issue# 1 (above), ...no plot appears on the (99% maximized) Plot Panel of Rstudio.
All the other examples in the post work GREAT, (except the last 2 exs). Mistery!
SFd99 ‘ggpubr’ version 0.2.5.999 Ubuntu Linux 18.04 w/ latest versions of Rstudio and R (3.6.3).
I would like to help but the error is not reproducible on my computer
Hi Kassambara, don't worry
- I'll continue to explore possibilities. Sometimes it's a small detail. Will let you know if I find a solution, in this thread.
Thanks again!.
Hi Kassambara,
as promised, I think _I found a SOLUTION (workaround) to Issue# 1 !! (= no plot is displayed).
If I type in Rstudio Console:
ggsummarystats( df, x = "dose", y = "len", ggfunc = ggboxplot, add = c("jitter"), color = "dose", palette = "jco", facet.by = c("supp", "qc"), labeller = "label_both", free.panels = TRUE, ggtheme = theme_bw(), legend = "top" ) Warning message: In stats::qt(alpha/2, .data$n - 1) : NaNs produced
and then, NO Plot shows up in the Plot panel of Rstudio. Just a blank Plot panel....
BUT... if I click on the "Refresh" icon (at top, right side icon of the Rstudio Plot panel, just next to the "Publish" icon), then after a few seconds, ....boom! wonderful ggpubr plot shows up OK!. :-)
Why pressing the Plot panel "Refresh" icon is needed, is a mystery!...
Does the error message (above), give any clue?.
By the way... if I use: free.panels = FALSE (instead of the example's: free.panels = TRUE) then the example works 100% . Plot shows OK!.
Any ideas/opinions?.
Thanks / Merci Kassambara! SFd99 San Francisco Rstudio 1.2.5033 Ubuntu Linux 18.04 R 3.6.3
MY LOADED PKGS:
attached packages:
[1] ggpubr_0.3.0
[2] rstatix_0.5.0
[3] janitor_2.0.1
[4] magrittr_1.5
[5] reshape2_1.4.4
[6] tidyr_1.0.2
[7] ggplot2_3.3.0
[8] dplyr_0.8.5
loaded via a namespace (and not attached):
[1] tidyselect_1.0.0
[2] purrr_0.3.4
[3] haven_2.2.0
[4] lattice_0.20-41
[5] carData_3.0-3
[6] tcltk_3.6.3
[7] snakecase_0.11.0
[8] colorspace_1.4-1
[9] vctrs_0.2.4
[10] generics_0.0.2
[11] expm_0.999-4
[12] rlang_0.4.6
[13] pillar_1.4.4
[14] foreign_0.8-76
[15] glue_1.4.0
[16] withr_2.2.0
[17] readxl_1.3.1
[18] lifecycle_0.2.0
[19] plyr_1.8.6
[20] stringr_1.4.0
[21] ggsignif_0.6.0
[22] munsell_0.5.0
[23] gtable_0.3.0
[24] cellranger_1.1.0
[25] ggsci_2.9
[26] zip_2.0.4
[27] mvtnorm_1.1-0
[28] labeling_0.3
[29] rio_0.5.16
[30] forcats_0.5.0
[31] manipulate_1.0.1
[32] curl_4.3
[33] broom_0.5.6
[34] Rcpp_1.0.4.6
[35] scales_1.1.0
[36] backports_1.1.6
[37] writexl_1.3
[38] abind_1.4-5
[39] farver_2.0.3
[40] gridExtra_2.3
[41] digest_0.6.25
[42] DescToolsAddIns_1.7
[43] hms_0.5.3
[44] stringi_1.4.6
[45] openxlsx_4.1.4
[46] cowplot_1.0.0
[47] grid_3.6.3
[48] tools_3.6.3
[49] DescTools_0.99.35
[50] tibble_3.0.1
[51] crayon_1.3.4
[52] car_3.0-7
[53] pkgconfig_2.0.3
[54] MASS_7.3-51.6
[55] ellipsis_0.3.0
[56] Matrix_1.2-18
[57] data.table_1.12.8
[58] lubridate_1.7.8
[59] assertthat_0.2.1
[60] rstudioapi_0.11
[61] R6_2.4.1
[62] boot_1.3-25
[63] nlme_3.1-147
[64] compiler_3.6.3
Thank you for the update, highly appreciated!
Would you please test the following script and tell me if it systematically works? This might help me to identify the root cause of issue 1....
library(ggpubr)
# Data preparation
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data("ToothGrowth")
df <- ToothGrowth
df$dose <- as.factor(df$dose)
# Add random QC column
set.seed(123)
qc <- rep(c("pass", "fail"), 30)
df$qc <- as.factor(sample(qc, 60))
# Create the plot
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pdf(NULL)
p <- ggsummarystats(
df, x = "dose", y = "len",
ggfunc = ggboxplot, add = c("jitter"),
color = "dose", palette = "jco",
facet.by = c("supp", "qc"), labeller = "label_both",
free.panels = TRUE,
ggtheme = theme_bw(), legend = "top"
)
x <- dev.off()
# Print the plot
p
Hi Kassambara,
Run the above code, but same result as before. After: Print the plot p
the Rstudio Plot Panel will turn all white, (as if "eager" to display the famous plot!), but no plot is displayed at all.
As before, clicking immediately on the "Refresh" plot icon (circular arrow at top, right) will display the plot ok, after a few seconds.
Plus, I now also noticed that the icon: "Previous" plot <= (blue arrow at top, left) becomes illuminated, (turns ON), as if there is a "previous" plot.
But of course, there is no "previous" plot ...another mystery symptom!.
Ok, thank you for the feedback. Let's keep this issue open. It seems to be related to this one #158 . ggarrange() might be the root cause. It is used to combine the different ggsummarystats() plot panels (p[["supp:OJ, qc:fail"]], p[["supp:OJ, qc:pass"]], etc) into one figure.
Yep... that sounds like a possibility f/ the Issue.
Kassambara, do you think it might (also) have some relationship with using: the "free.panels" code (T/F)?.
If you use: free.panels = FALSE (instead of the example's: free.panels = TRUE) then the example works 100% .
Plot shows OK immediately!. (although not exactly the same plot ...but it shows ok!.
I get a similar error too.
Warning messages: 1: In stats::qt(ci/2 + 0.5, data_sum$length - 1) : NaNs produced
But if I remove add = "mean_se", from the code, the warning disappears and the plot is generated although without the error bars.
What could be the issue?