

I know what I want to do is get filter the highest y value (of the error bars) at each time point to transform by adding a fixed value for space for the label (a, b, c, d, e, or f ) above the error bar. I’ve started using a sequence of ggpubr::stat_compare_means where each instance is a different group and manually adjusting the y position to stack the marks but this is not sophisticated. This is not a fast process but all the ggplot2 modifier packages are not compatible with geom_line. I have been using ggpubr::compare_means to get the comparison results and then calling annotate() to manually adjust a vector of 8 x and y values to add a label of a,b,c,d,e,f. upper.How can I visually represent significant differences from a multiple comparisons t.test between 4 independent groups at 8 time points on a line plot? Basically, I want to add (*) to stat_summary(geom = “line”). Stat_boxplot(geom = "hline", aes(yintercept =. Geom_boxplot(aes(fill = cut, group = cut)) + Geom_polygon(data = p.density.data, aes(x = y, y = x), Ggplot(diamonds, aes(x = -0.5, y = carat)) + Mutate(cut = factor(group, labels = levels(diamonds$cut), ordered = TRUE)) %>% Geom_density(data = diamonds, aes(x = carat)) +Īlternative 2: calculate the density plot's coordinates, & flip them manually before passing the results to ggplot(). %>% select(cut, lower, middle, upper) %>% gather(key, value, -cut),

Geom_rect(aes(xmin = lower, xmax = upper, ymin = -0.75, ymax = -0.25, fill = cut), Mutate(cut = factor(x, labels = levels(diamonds$cut), ordered = TRUE)) %>% Select(x, ymin, lower, middle, upper, ymax, outliers) %>% Add a density layer in the normal way: library(dplyr) If you are limited to the ggplot2 package for one reason or another, it can still be done, but it would be less straightforward, since geom_boxplot() and geom_density() go in different directions.Īlternative 1: calculate the box plot's coordinates, & flip them manually before passing the results to ggplot(). # in viridis scale by default, using the current version of ggplot2) # reproduce original chart's color scale (o/w ordered factors will result Stat_boxploth(geom = "vline", aes(xintercept =. This can be done easily with a horizontal boxplot geom_boxploth() / stat_boxploth(), found in the ggstance package: library(ggstance) Stat_boxplot(geom = "vline", aes(xintercept =. Geom_density(aes(x = carat), inherit.aes = FALSE) + Ggplot(diamonds, aes(x = carat, y = -0.5)) + The following will now work directly (replacing all references to geom_boxploth / stat_boxploth in the original answer with geom_boxplot / stat_boxplot: library(ggplot2) The aesthetic mapping, but can also be specified directly with the new Had different interpretation), can now freely choose their direction,

Under the package's news, under new features:Īll geoms and stats that had a direction (i.e. Edit: As of ggplot2 3.3.0, this can be done in ggplot2 without any extension package.
