ggpubr

R - reformat P value in ggplot using 'stat_compare_means'

流过昼夜 提交于 2021-02-18 19:00:28
问题 I want to plot the p values to each panel in a faceted ggplot. If the p value is larger than 0.05, I want to display the p value as it is. If the p value is smaller than 0.05, I want to display the value in scientific notation (i.e, 0.0032 -> 3.20e-3; 0.0000425 -> 4.25e-5). The code I wrote to do this is: p1 <- ggplot(data = CD3, aes(location, value, color = factor(location), fill = factor(location))) + theme_bw(base_rect_size = 1) + geom_boxplot(alpha = 0.3, size = 1.5, show.legend = FALSE)

ggpubr: change font size of stat_compare_means Kruskal-Wallis p-values

淺唱寂寞╮ 提交于 2021-02-07 07:52:19
问题 How can I change the font size of stat_compare_means on the plot below? I.e, change the "Kruskal-Wallis, p = 1.5e-09" and the other p-values font size? I would like to use a smaller font size than the default one... Following the data example... library(ggpubr) data("ToothGrowth") compare_means(len ~ dose, data = ToothGrowth) # Visualize: Specify the comparisons I want my_comparisons <- list( c("0.5", "1"), c("1", "2"), c("0.5", "2") ) # Plotting ggboxplot(ToothGrowth, x = "dose", y = "len",

Add P values to comparisons within groups boxplot

[亡魂溺海] 提交于 2021-02-05 07:56:50
问题 I'm trying to create a boxplot which shows only the significant p values, within the groups for each bar in a box plot. For example here it would compare I1 and SI2 for the "fair", "good", "very good" etc I've tried using the following code to achieve the above plot library(ggplot2) library(dplyr) data("diamonds") labeldat <- diamonds %>% group_by(cut, clarity) %>% dplyr::summarise(labels = paste(n(), n_distinct(color), sep = "\n")) Comparisons = list(c("I1","SI2"),c("I1","SI1"),c("I1","VS2")

Plot pvalue information for mean comparisons by grouping variable

前提是你 提交于 2021-01-21 10:01:12
问题 I've put together a plot to view groups separately but now want to include significance levels for mean pairwise comparison in the plot. While I can do the comparison outside of the plot I'm wondering what the most efficient way of including the comparison in the plot would be? Current Plot library(tidyverse) dsub <- diamonds[ sample(nrow(diamonds), 10000), ] dsub <- dsub %>% filter(clarity %in% c('VS2', 'VS1', 'VVS2')) ggplot(dsub, aes(x = cut, y = carat, fill = clarity)) + geom_boxplot

ggpubr::ggarrange save plots over multiple pages with one legend per page

痴心易碎 提交于 2020-06-13 09:32:34
问题 I'm trying to save plots over multiple pdf plots with one overall legend per page. I'm wondering is there a neat way to use ggsave and ggpubr::ggarrange to do this? Changing nrow ncol within ggarrange only changes the setup for one page and forces all plots to be on the same page (not over a few pages). library(ggplot2) library(ggpubr) plot_f <- function(df, xx) { df %>% filter(carb == xx) %>% ggplot() + geom_line(aes(x = disp, y = hp, colour = "darkblue" )) + geom_line(aes(x = disp, y = qsec

ggpubr::ggarrange save plots over multiple pages with one legend per page

爷,独闯天下 提交于 2020-06-13 09:31:07
问题 I'm trying to save plots over multiple pdf plots with one overall legend per page. I'm wondering is there a neat way to use ggsave and ggpubr::ggarrange to do this? Changing nrow ncol within ggarrange only changes the setup for one page and forces all plots to be on the same page (not over a few pages). library(ggplot2) library(ggpubr) plot_f <- function(df, xx) { df %>% filter(carb == xx) %>% ggplot() + geom_line(aes(x = disp, y = hp, colour = "darkblue" )) + geom_line(aes(x = disp, y = qsec

Can we neatly align the regression equation and R2 and p value?

别来无恙 提交于 2020-06-07 04:30:07
问题 What is the best (easiest) approach to add neatly to a ggplot plot the regression equation, the R2, and the p-value (for the equation)? Ideally it should be compatible with groups and faceting. This first plot with has the regression equation plus the r2 and p-value by group using ggpubr , but they are not aligned? Am I missing something? Could they be included as one string? library(ggplot) library(ggpubr) ggplot(mtcars, aes(x = wt, y = mpg, group = cyl))+ geom_smooth(method="lm")+ geom

Correct positioning of multiple significance labels in ggplot

依然范特西╮ 提交于 2020-05-14 12:11:05
问题 I want to present two groups with their development over time in a boxplot, and add labels of significance for each group (intra-group comparisons). I have a working example using ggpubr::stat_compare_means , but I am unable to correctly position the two geoms. I have attempted position = position_dodge(width=0.5) and several other positional elements, but for some reasons they wont move at all. My desired output would have each label set horizontally shifted to be over each groups box, and