boxplot

Boxplot: colors by x value and hues differentiated by pattern

寵の児 提交于 2019-11-29 15:57:46
Say I have a boxplot like the one shown below: I would like to achieve a different coloring: Fri , Sat and Sun would be colored blue; Thur would be colored red I would like to differentiate hues with a pattern in the box (stripped or something) I can't find a way to do this manipulation using seaborn palette. I know I can mess with the boxes of a boxplot in matplotlib directly but seaborn gives me the axes back. How can I get the boxes in this case? The boxes end up in the artists list on the returned axes, so you just need to manipulate the attributes on those objects: ax = sns.boxplot(data=x

Matplotlib Boxplot: Showing Number of Occurrences of Integer Outliers

丶灬走出姿态 提交于 2019-11-29 15:43:07
I have a plot like the following (using plt.boxplot() ): Now, what I want is plotting a number how often those outliers occured (preferably to the top right of each outlier). Is that somehow achievable? ax.boxplot returns a dictionary of all the elements in the boxplot. The key you need here from that dict is 'fliers' . In boxdict['fliers'] , there are the Line2D instances that are used to plot the fliers. We can grab their x and y locations using .get_xdata() and .get_ydata() . You can find all the unique y locations using a set , and then find the number of fliers plotted at that location

How to extend ggplot2 boxplot with ggproto?

Deadly 提交于 2019-11-29 14:43:23
问题 I'm often using boxplots in my work and like ggplot2 aesthetics. But standard geom_boxplot lacks two things important for me: ends of whiskers and median labels. Thanks to information from here I've written a function: gBoxplot <- function(formula = NULL, data = NULL, font = "CMU Serif", fsize = 18){ require(ggplot2) vars <- all.vars(formula) response <- vars[1] factor <- vars[2] # A function for medians labelling fun_med <- function(x){ return(data.frame(y = median(x), label = round(median(x

R ggplot2: boxplots with significance level (more than 2 groups: kruskal.test and wilcox.test pairwise) and multiple facets

拥有回忆 提交于 2019-11-29 12:56:48
Following up on this question , I am trying to make boxplots and pairwise comparisons to show levels of significance (only for the significant pairs) again, but this time I have more than 2 groups to compare and more complicated facets. I am going to use the iris dataset here for illustration purposes. Check the MWE below where I add an additional "treatment" variable. library(reshape2) library(ggplot2) data(iris) iris$treatment <- rep(c("A","B"), length(iris$Species)/2) mydf <- melt(iris, measure.vars=names(iris)[1:4]) ggplot(mydf, aes(x=variable, y=value, fill=Species)) + geom_boxplot() +

Adding points to horizontal boxplots

对着背影说爱祢 提交于 2019-11-29 12:44:05
I use the following code to produce multiple boxplots, ranked by the mean value of the variables: zx <- replicate (5, rnorm(50)) zx_means <- (colMeans(zx, na.rm = TRUE)) colnames (zx) <- seq_len (ncol (zx)) boxplot(zx [, order (zx_means)], horizontal = FALSE, outline = FALSE) points(zx_means [ order (zx_means)], pch = 22, col = "darkgrey", lwd = 7) ( See this post for more details ) When I change the code to horizontal = TRUE , I'm not able to make the points line up with the boxplots. Any ideas for how to properly add points to horizontal boxplots? cbeleites You need to give both x and y

R ggplot2 - perform pairwise tests per pair in a facet and show the p-values with ggsignif

微笑、不失礼 提交于 2019-11-29 12:34:07
Following up on this question I posted some days ago, I want to perform something similar. Given the following MWE: ############################## ##MWE library(ggplot2) library(ggsignif) set.seed(1) alpha.subA <- data.frame(Sample.ID=paste(sample(LETTERS, 163, replace=TRUE), sample(1:1000, 163, replace=FALSE), sep=''), Group=c(rep('C',10),rep('FH',10),rep('I',19),rep('IF',42),rep('NA',14),rep('NF',42),rep('NI',15),rep('NS',10),rep('PGMC4',1)), Value=rnorm(n=163)) alpha.subA$DB <- "DATABASE1" set.seed(2) alpha.subB <- data.frame(Sample.ID=paste(sample(LETTERS, 163, replace=TRUE), sample(1:1000

Multiple box plots within one group

ε祈祈猫儿з 提交于 2019-11-29 10:24:34
问题 I found some solutions but not exactly what I want. I have 5 dataframes in R and each dataframe has 4 columns: Lets say name of the first dataframe is "Gene1" Ind1 Ind2 Ind3 Ind4 1 3 3.2 2.5 1 3 4 2 1.5 2 2.2 1 3.4 2 1 3 and remaining dataframes are called "Gene2", "Gene3","Gene4","Gene5" and are similar. I want to plot boxplots side by side in same plot for all dataframes and for all columns. I did not find any plot like this, so I can't upload a picture but I will try to explain. Now from

Remove whiskers in box-whisker-plot

馋奶兔 提交于 2019-11-29 10:14:42
Is there a straightforward way to remove the whiskers from a box-whisker-plot in ggplot2 in R ? I'd like to keep only the boxes themselves. MWE: library("ggplot2") p <- ggplot(mtcars, aes(factor(cyl), mpg)) p + geom_boxplot(outlier.size = 0) We only need to add the argument coef = 0 : library(ggplot2) p <- ggplot(mtcars, aes(factor(cyl), mpg)) p + geom_boxplot(outlier.size = 0, coef = 0) One way would be to use stat_summary_df() to calculate meadian, 25 and 75 percentiles and then plot those data with geom="crossbar" . Automatically it can be done with "median_hilow" inside the stat_summary_df

Set space between boxplots in Python Graphs generated nested box plots with Seaborn?

强颜欢笑 提交于 2019-11-29 07:17:18
I am trying to set a space between the boxplots (between the green and orange boxes) created with Python Seaborn module's sns.boxplot() . Please see attached the graph, that the green and orange subplot boxes are stuck to each other, making it visually not the most appealing. Can't find a way to do that, anyone could find a way (code attached)? import numpy as np import pandas as pd import matplotlib as mpl import matplotlib.pyplot as plt import seaborn as sns tips = sns.load_dataset("tips") sns.set(style="ticks", palette='Set2', font='Roboto Condensed') sns.set_context("paper", font_scale=1.1

how to align violin plots with boxplots

久未见 提交于 2019-11-29 07:02:46
问题 I have this data frame set.seed(1234) x <- rnorm(80, 5, 1) df <- data.frame(groups = c(rep("group1",20), rep("group2",20), rep("group3",20), rep("group4",20)), value = x, type = c(rep("A", 10), rep("B", 10), rep("A", 10), rep("B", 10), rep("A", 10), rep("B", 10), rep("A", 10), rep("B", 10))) And I would like to plot it as violin plot, aligned with a narrow box plot and grouped by the variable type: ggplot(data = df, aes(x = groups, y = value, fill = type)) + geom_violin()+ geom_boxplot(width=