boxplot

Getting data of a box plot - Matplotlib

冷暖自知 提交于 2019-12-04 12:01:57
I have to plot a boxplot of some data, which I could easily do with Matplotlib . However, I was requested to provide a table with the data presented there, like the whiskers, the medians, standard deviation, and so on. I know that I could calculate these "by hand", but I also know, from the reference, that the boxplot method: Returns a dictionary mapping each component of the boxplot to a list of the matplotlib.lines.Line2D instances created. That dictionary has the following keys (assuming vertical boxplots): boxes: the main body of the boxplot showing the quartiles and the median’s

How to display two groups of boxplots?

人走茶凉 提交于 2019-12-04 11:44:30
I have two groups of data (x1 and x2 versus y1 and y2), which I would like to display as two groups of boxplots. I tried the following, but it displays the wrong data because the vectors x1 and x2 (and y1 and y2) are not of the same lengths: x1 <- c(2,3,4) x2 <- c(0,1,2,3,4,5) y1 <- c(3,4,5) y2 <- c(1,2,3,4,5,6) d0 <- matrix(c(x1, x2), ncol=2) d1 <- matrix(c(y1, y2), ncol=2) lmts <- range(d0,d1) par(mfrow = c(1, 2)) boxplot(d0, ylim=lmts, xlab="x") boxplot(d1, ylim=lmts, xlab="y") This is what it shows (of course, I wanted the whiskers of the first boxplot to go from 2 to 4 instead, according

Displaying separate means within fill groups in ggplot boxplot

两盒软妹~` 提交于 2019-12-04 11:35:45
问题 I have a grouped boxplot using data with 3 categories. One category is set as the x-axis of the boxplots, the other is set as the fill, and the last one, as a faceting category. I want to display the means for each fill group, but using stat_summary only gives me the mean for the x-axis category, without separating the means for the fill: Here is the current code: demoplot<-ggplot(demo,aes(x=variable,y=value)) demoplot+geom_boxplot(aes(fill=category2),position=position_dodge(.9))+ stat

Multiple boxplots on one plot with ggplot2

爷,独闯天下 提交于 2019-12-04 11:03:29
Standard R plotting produces 30 boxplots in one plot when I use this code: boxplot(Abundance[Quartile==1]~Year[Quartile==1],col="LightBlue",main="Quartile1 (Rare)") I would like to produce something similar in ggplot2. So far i'm using this: d1 = data.frame(x=data$Year[Quartile==1],y=data$Abundance[Quartile==1]) a <- ggplot(d1,aes(x,y)) a + geom_boxplot() There are 30 years of data. In each year there are 145 species. In each year the 145 species are categorized into quartiles of 1-4. However, I'm only getting a single boxplot using this. Any idea how to get 30 boxplots (one for each year)

Coloring only the median in the boxplot

青春壹個敷衍的年華 提交于 2019-12-04 09:54:28
Is there a way to color only the median line of the boxplot and not the whole boxplot. When I try this : boxplot(matrix,col="red") then the whole box gets red colored. I want to color only the median line of the boxplot. Is there a way to do it in R ?? Try medcol as in boxplot(matrix(rnorm(100), ncol=2), medcol="red") 来源: https://stackoverflow.com/questions/10071371/coloring-only-the-median-in-the-boxplot

ggplot2 : multiple factors boxplot with scale_x_date axis in R

家住魔仙堡 提交于 2019-12-04 09:04:34
I would like to create a multivariate boxplot time serie with ggplot2 and i need to have an x axis with boxplot position function of dates. I created for that an interaction matrix with the combination of the factors Treatment x Date that is plotted against NDVI and with different trial groups: here you can find some minimal data : dat<-"Treatment Trial.group Date NDVI HighN A 14/06/2013 0.27522123 HighN A 14/06/2013 0.259781926 HighN A 14/06/2013 0.175982276 LowN A 14/06/2013 0.193604644 LowN A 14/06/2013 0.261191793 LowN A 14/06/2013 0.273672853 HighN B 14/06/2013 0.192144884 HighN B 14/06

Histogram with marginal boxplot in R

扶醉桌前 提交于 2019-12-04 07:25:31
How make matching X-axis in histogram with marginal boxplot? data <- rnorm(1000) nf <- layout(mat = matrix(c(1,2),2,1, byrow=TRUE), height = c(1,3)) layout.show(nf) par(mar=c(5.1, 4.1, 1.1, 2.1)) boxplot(data, horizontal=TRUE, outline=FALSE) hist(data) One solution would be to set ylim= in boxplot() to the same range as xlim= in hist() . set.seed(123) data <- rnorm(1000) nf <- layout(mat = matrix(c(1,2),2,1, byrow=TRUE), height = c(1,3)) par(mar=c(5.1, 4.1, 1.1, 2.1)) boxplot(data, horizontal=TRUE, outline=FALSE,ylim=c(-4,4)) hist(data,xlim=c(-4,4)) Using ggplot and grid package. library

plot line over boxplot using pandas DateFrame

孤者浪人 提交于 2019-12-04 06:58:01
I have a pandas DateFrame with 16 columns corresponding years (2000 to 2015) and 12 lines with values for each month. I'm trying plot a boxplot and a line with 2015 values in same fig in order to compare, using this code: import pandas as pd import matplotlib.pyplot as plt df = pd.read_excel('hidro_ne.xlsx') fig, ax = plt.subplots() ax1 = df[2015].plot(ax=ax, linewidth=2, legend='2015',color='red') df.T.plot.box(yticks=range(0, 100, 5), ax=ax1) plt.show() In 2015 column I have data from January until September, but I get a shift line plot, from yline until september: In fact the line should

How to modify whiskers of a boxplot in ggplot2?

孤人 提交于 2019-12-04 06:45:22
I'll start with an MWE: library(ggplot2) p <- ggplot(mtcars, aes(factor(cyl), mpg, fill = factor(am))) p + geom_boxplot() I'd like to modify the colour of the whiskers, e.g., set it to red. I don't think it's possible to do this directly both geom_boxplot , so this is my workaround: library(Hmisc) stat_sum_df <- function(fun, geom = "crossbar", ...) { stat_summary(fun.data = fun, geom = geom, width = 0.4, ...) } p + stat_boxplot(geom = 'linerange', colour = "red", position = "dodge) + stat_sum_df("median_hilow", conf.int = 0.5, position = "dodge") The line ranges are stacked on top of each

ggplot2: Boxplots with points and fill separation [duplicate]

有些话、适合烂在心里 提交于 2019-12-04 06:28:36
This question already has answers here : Closed 2 years ago . ggplot2 - jitter and position dodge together (2 answers) I have a data which can be divaded via two seperators. One is year and second is a field characteristics. box<-as.data.frame(1:36) box$year <- c(1996,1996,1996,1996,1996,1996,1996,1996,1996, 1997,1997,1997,1997,1997,1997,1997,1997,1997, 1996,1996,1996,1996,1996,1996,1996,1996,1996, 1997,1997,1997,1997,1997,1997,1997,1997,1997) box$year <- as.character(box$year) box$case <- c(6.40,6.75,6.11,6.33,5.50,5.40,5.83,4.57,5.80, 6.00,6.11,6.40,7.00,NA,5.44,6.00, NA,6.00, 6.00,6.20,6.40