csdaw / ggprism Goto Github PK
View Code? Open in Web Editor NEWggplot2 extension inspired by GraphPad Prism
Home Page: https://csdaw.github.io/ggprism/
ggplot2 extension inspired by GraphPad Prism
Home Page: https://csdaw.github.io/ggprism/
I generate a lot of graphs of the same type. And they all have a different scale along the y-axis. And the step.increase default value is not suitable, because the lines on the graph with the p-value stick together. If I change the step.increase standard value, then the lines, on the contrary, diverge too much.
stat.test <- total %>% rstatix::wilcox_test(as.formula(paste(col_names[col_i], "group", sep="~" ))) %>% rstatix::add_y_position()
stat.test$y.position[3] = stat.test$y.position[1]
Hi!
i chanced upon your package and was wondering how i can add new themes to it?
Thank you very much and look forward to hearing back from you.
Need to release a patch so p-value vignette passes CRAN checks. Otherwise ggprism will get removed from CRAN ๐ต
To do:
Prepare for resubmission:
README.Rmd
R CMD check
devtools::check(remote = TRUE, manual = TRUE)
NEWS.md
devtools::check_win_devel()
rhub::check_for_cran()
*cran-comments.md
*I used:
rhub::check_for_cran(
platforms = c("fedora-clang-devel",
"windows-x86_64-oldrel"),
env_vars=c(
`_R_CHECK_FORCE_SUGGESTS_` = "true",
`_R_CHECK_CRAN_INCOMING_USE_ASPELL_` = "true",
R_COMPILE_AND_INSTALL_PACKAGES = "always"
)
)
Submit to CRAN:
usethis::use_version("patch")
devtools::submit_cran()
Wait for CRAN...
usethis::use_github_release()
usethis::use_dev_version()
Small release mainly to preserve compatibility with ggplot2 v3.4.0 (but also fixes a bug and adds a small feature, see NEWS.md).
Prepare for submission:
NEWS.md
url_checker::url_check()
R CMD check
devtools::check(remote = TRUE, manual = TRUE)
revdepcheck::revdep_check(num_workers = 4)
Optionally fix things that need fixing, then repeat the above.
Submit to CRAN:
devtools::check_win_devel()
rhub::check_for_cran()
*cran-comments.md
usethis::use_version("patch")
devtools::build_readme()
devtools::submit_cran()
Wait for CRAN...
usethis::use_github_release()
usethis::use_dev_version()
*I used:
rhub::check_for_cran(
platforms = c("fedora-clang-devel", "windows-x86_64-oldrel"),
env_vars=c(
`_R_CHECK_FORCE_SUGGESTS_` = "true",
`_R_CHECK_CRAN_INCOMING_USE_ASPELL_` = "true",
`R_COMPILE_AND_INSTALL_PACKAGES` = "always"
)
)
Prepare for release:
devtools::build_readme()
R CMD check
devtools::check(remote = TRUE, manual = TRUE)
devtools::check_win_devel()
rhub::check_for_cran()
*cran-comments.md
and push*I used:
rhub::check_for_cran(env_vars=c(`_R_CHECK_FORCE_SUGGESTS_` = "true",
`_R_CHECK_CRAN_INCOMING_USE_ASPELL_` = "true",
R_COMPILE_AND_INSTALL_PACKAGES = "always"))
Submit to CRAN:
usethis::use_version("patch")
devtools::submit_cran()
Wait for CRAN...
Need to fix issues and resubmit.
Need to release a patch so tests won't fail when ggplot2 v3.4.0 is released.
Prepare for resubmission:
devtools::build_readme()
url_checker::url_check()
R CMD check
devtools::check(remote = TRUE, manual = TRUE)
NEWS.md
devtools::check_win_devel()
rhub::check_for_cran()
*cran-comments.md
Submit to CRAN:
usethis::use_version("patch")
devtools::submit_cran()
Wait for CRAN...
usethis::use_github_release()
usethis::use_dev_version()
*I used:
rhub::check_for_cran(
platforms = c("fedora-clang-devel", "windows-x86_64-oldrel"),
env_vars=c(
`_R_CHECK_FORCE_SUGGESTS_` = "true",
`_R_CHECK_CRAN_INCOMING_USE_ASPELL_` = "true",
`R_COMPILE_AND_INSTALL_PACKAGES` = "always"
)
)
Hi @csdaw,
I am using the add_pvalue
function, and I am wondering whether it would be possible to have the P values nicely formatted as P = 1x10-10 rather than P=1e-10. For doing this, I usually use latex2exp::TeX
but I don't understand how to integrate it into the add_pvalue
function.
I am now using rstatix
to both perform the statistical test and create the p-value table with the correct x and y position:
p <- ggplot(ToothGrowth, aes(x = factor(dose), y = len)) +
geom_boxplot(aes(fill = dose), colour = "black") +
theme_prism() +
theme(legend.position = "none")
stat.test <- rstatix::t_test(ToothGrowth, len ~ dose, ref.group = "0.5") %>%
rstatix::add_xy_position()
My first thought was to create a new field in stat.test
to store the LaTeX expressions generated by latex2exp::TeX
, as follows:
stat.test$p.latex <- latex2exp::TeX(stat.test$p.latex)
where p.latex
Is a string vector containing LaTeX expressions (let's say "1 \\times 10^{-10}"
) which I generated with another function.
However, the stats.test
object is not able to store expressions (as those outputted by latex2exp::TeX
).
I then tried to modify the
p + add_pvalue(stat.test, label = "p = {p.latex}")
bit and the add_pvalue
function to have the expression printed, but I have no idea on how to do this.
Would you be able to help me?
Many thanks in advance!
Hi
We are preparing the next version of ggplot2 and our tests show that ggprism is having issues with it. Specifically we now store the computed params in computed_geom_params
and computed_stat_params
. This means that these are the field you should be expecting in your tests if you feel it necessary to peek into the ggplot object.
The failing tests are:
----- FAILED[data]: test-annotation_ticks.R<66--66>
call| expect_true(g1$layers[[2]]$geom_params$colour == "red")
diff| Expected TRUE, got 'logical' of length 0
----- FAILED[data]: test-annotation_ticks.R<69--69>
call| expect_true(g2$layers[[2]]$geom_params$colour == "red")
diff| Expected TRUE, got 'logical' of length 0
where you should look at g1$layers[[2]]$computed_geom_params$colour
instead
we plan to release the next version of ggplot2 on May 31st
Hey there,
I am currently running the following R code:
p_vals <- tibble::tribble(
~group1, ~group2, ~p.adj, ~y.position,
"audi", "dodge", 0.01 , 3.99,
"audi", "chevrolet", 0.01, 3.5
)
mpg %>%
mutate(displ = as.numeric(displ)) %>%
ggplot(aes(x = manufacturer, y = displ, fill = manufacturer))+
geom_bar(position=position_dodge(), stat="identity") +
geom_jitter(height = 0, width = 0.2, size = 4) +
ylim(0,4) +
theme_prism(base_size = 16)+
scale_fill_manual(values = cbbPalette)+
theme(legend.position = "none") +
add_pvalue(p_vals, label = "p = {p.adj}", tip.length = 0, label.size = 4)
And receiving the following error:
Error:
! Problem while computing aesthetics.
โน Error occurred in the 3rd layer.
Caused by error in `FUN()`:
! object 'manufacturer' not found
Backtrace:
1. base (local) `<fn>`(x)
2. ggplot2:::print.ggplot(x)
4. ggplot2:::ggplot_build.ggplot(x)
5. ggplot2:::by_layer(...)
12. ggplot2 (local) f(l = layers[[i]], d = data[[i]])
13. l$compute_aesthetics(d, plot)
14. ggplot2 (local) compute_aesthetics(..., self = self)
15. base::lapply(aesthetics, eval_tidy, data = data, env = env)
16. rlang (local) FUN(X[[i]], ...)
Error in (function (mapping = NULL, data = NULL, stat = "bracket", position = "identity", :
โน Error occurred in the 3rd layer.
Caused by error in `FUN()`:
! object 'manufacturer' not found
When I run the same code without the add_pvalues()
command, it creates the plot. I can also add pvalue lines with geom_signif(), but those stay small / don't get larger with the theme_prism(base_size=16)
argument so I'd like to make the add_pvalues() arg work .
Thanks for any advice! Not sure how to fix this one~
I tried to add the legend title to my data, but I found that if I added theme_prism(base_size = 14) my legend title would disappear, if I commented this out the legend title would appear again, I don't know what is wrong, can someone help me?
I used R4.1.3 and downloaded prism version 1.0.2
Things to include in the future:
.pzfx
file with examples and a vignette recreating them with this package. Or even a pkgdown site...Some features/functions of other packages would fit in ggprism, but I don't want to extend the dependencies of ggprism beyond those of ggplot2. So need to rewrite them into ggprism.
geom_signif
from const-ae/ggsignif and stat_pvalue_manual
from kassambara/ggpubrHi,
I've got this error when I updated the ggplot2 to the latest version 3.4.4.9000. The
legend.text.align theme element is not defined in the element hierarchy.
I think it has something to do with ggplot2 deprecating the legend.text.align
argument of theme()
.
Thanks!
Fixes compatibility with ggplot2 v3.5.0.
Prepare for submission:
NEWS.md
urlchecker::url_check()
R CMD check
devtools::check(remote = TRUE, manual = TRUE)
revdepcheck::revdep_check(num_workers = 4)
Optionally fix things that need fixing, then repeat the above.
Submit to CRAN:
devtools::check_win_devel()
rhub::check_for_cran()
*cran-comments.md
usethis::use_version("patch")
devtools::build_readme()
devtools::submit_cran()
Wait for CRAN...
usethis::use_github_release()
usethis::use_dev_version()
*I used:
rhub::check_for_cran(
platforms = c("fedora-clang-devel", "windows-x86_64-oldrel"),
env_vars=c(
`_R_CHECK_FORCE_SUGGESTS_` = "true",
`_R_CHECK_CRAN_INCOMING_USE_ASPELL_` = "true",
`R_COMPILE_AND_INSTALL_PACKAGES` = "always"
)
)
Hi
We preparing the next release of ggplot2 and our reverse dependency checks show that your package is failing with the new version. Looking into it we see that your package somehow includes references to ggplot2 code from when it was build, either by reloading saved plot objects or by grabbing functions at build time. Please see https://www.tidyverse.org/blog/2022/09/playing-on-the-same-team-as-your-dependecy/ for some more info about why this can cause issues.
You can install the release candidate of ggplot2 using devtools::install_github('tidyverse/[email protected]')
to test this out.
We plan to submit ggplot2 by the end of October and hope you can have a fix ready before then
Kind regards
Thomas
Hi first of all great package! However I have an issues with hiding the legend....adding:
plot + theme(legend.title = element_blank()) doesnt seem to work....adding show.legend = F to the aes of ggplot does work but every time I add plot + theme_prism() the legend pops back up
This is an option in stat_pvalue_manual to hide insignificant p values from being plotted and seems to be missing from add_pvalue function. Would you be able to add it?
Thank you for your great work.
I found a problem with the label.
The problem is that;
An "i" in the label string is forced to be capitalized.
iris %>% ggplot(aes(x = Sepal.Length, y = Sepal.Width, color = Species))+ geom_point()+ xlab("all small iiiiis")+ theme_prism()
iris %>% ggplot(aes(x = Sepal.Length, y = Sepal.Width, color = Species))+ geom_point()+ xlab("all small iiiiis")+ theme_bw()
my environment is;
Mac mini (M1)
R version 4.4.0 (2024-04-24) -- "Puppy Cup"
Rstudio (2024.04.0+735)
ggprism_1.0.5
ggplot2_3.5.1
In no particular order
guide_prism_minor
and make changes more explicitggplot-internal.R
and replace with pulls from ggplot2 NAMESPACE (see teunbrand/ggh4x)annotation_ticks
is useful or can be removedannotation_ticks
ggprism-package.R
or should be moved to the functions in which they are usedscale_fill_prism
has the correct structurescale_shape_prism
has the correct structuretheme_prism
inherit from base_line_size
? Not sure about this one...frame = TRUE
in theme_prism
, or at least play around with panel.borderscale_colour/color_prism
functionsscale_colour_prism
data-raw
more consistent.pdf
with all colour schemesannotation_ticks
ggprism-package
ggprism_data
guide_prism_minor
scale_fill_prism
scale_colour_prism
scale_shape_prism
theme_prism
annotation_ticks
guide_prism_minor
scale_fill_prism
scale_colour_prism
scale_shape_prism
theme_prism
Hello
I have been using your wonderful package, unfortunately, I started getting errors across all of my Rmarkdown and scripts. This started happening about a week ago.
For example:
p_HR_all <- final_result %>% ggplot(aes(x = Time, y = HR, color=Group)) + geom_smooth(method = "loess", se = TRUE) + labs(title = "", x = "Time (seconds)", y = "HR (bpm)") + theme_prism() + scale_x_continuous(limits = c(0, 180), breaks = seq(0, 180, 60)) p_HR_all
and the error would be:
Error in plot_theme()
:
! The legend.text.align
theme element is not defined in the element hierarchy.
Backtrace:
<fn>
(x)hopefully is a quick fix. Thank you
Hello,
I'm new to plotting p-values on interaction plots, and I've been working off the piece of code below (source).
I've been trying to adjust the x-position of the brackets, such that for each pairwise comparison, the left end of the bracket is aligned with the middle of the first boxplot being considered, and the right end of the bracket is aligned with the middle of the second boxplot being considered.
In other words, I would like xmin in df_p_val to reflect the dose & supp combination of the first group in the pairwise comparison -- not just its dose.
Thank you very much in advance for any guidance you may be able to provide!
df_p_val <- ToothGrowth %>%
rstatix::group_by(supp) %>%
rstatix::t_test(len ~ dose) %>%
rstatix::add_xy_position()
p <- ggplot(ToothGrowth, aes(x = factor(dose), y = len)) +
geom_boxplot(aes(fill = supp)) +
theme_prism()
# remember colour and step.group.by are referring to a column name in df_p_val
p + add_pvalue(df_p_val,
label = "p = {p.adj}",
colour = "supp",
fontface = "bold",
step.group.by = "supp",
step.increase = 0.1,
tip.length = 0,
bracket.colour = "black",
show.legend = FALSE)
add_pvalue function affects scale_y_log10's behavior, e.g.
tg <- ToothGrowth
tg$dose <- as.factor(tg$dose)
tg$group <- factor(rep(c("grp1", "grp2"), 30))
two.means <- tibble::tribble(
~group1, ~group2, ~p, ~y.position,
"OJ", "VC", 0.0606, 36)
Without scale_y_log10, add_pvalue works as expected
ggplot(tg, aes(x = supp, y = len)) + geom_boxplot() + add_pvalue(two.means)
With scale_y_log10, y-axis become extremely large and original plots are squeezed to the bottom
ggplot(tg, aes(x = supp, y = len)) + geom_boxplot() + add_pvalue(two.means) + scale_y_log10()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.