boxplot

can one offset jitter points in ggplot boxplot

笑着哭i 提交于 2019-12-19 08:13:37
问题 In a ggplot boxplot , it is easy to use jitter to add the raw data points with varying degrees of jitter. With zero jitter the following code dat <- data.frame(group=c('a', 'b', 'c'), values = runif(90)) ggplot(dat, aes(group, values)) + geom_boxplot(outlier.size = 0) + geom_jitter(position=position_jitter(width=0), aes(colour=group), alpha=0.7) + ylim(0, 1) + stat_summary(fun.y=mean, shape=3, col='red', geom='point') + opts(legend.position = "right") + ylab("values") + xlab("group") produces

ggplot: how to specify vertical order of multiple boxplots?

家住魔仙堡 提交于 2019-12-19 08:06:28
问题 I would like to change the stacking order of hospitals in the diagram below so #1 is at the top and #4 at the bottom. The diagram was produced with ggplot(survey,aes(x=hospital, y=age))+geom_boxplot()+coord_flip()+xlab("")+ylab ("\nPatient Age") and I need the top->down order to be the reverse of what is now. I'm not sure why it comes the way it does now. The 'hospital' column is a factor in case it matters. Many thanks! 回答1: You have a few options. The easiest would be to add p + scale_x

How to make a base R style boxplot using ggplot2?

折月煮酒 提交于 2019-12-19 05:47:09
问题 I need to make a lot of boxplots for an upcoming publication. I would like to use ggplot2 because I think it will be more flexible for future projects, but my PI is insisting that I make these plots in the style of base-R. He specifically wants the dashed lines, so that they will appear similar to previous plots we made. I have made an example using the iris dataset to show you, using this code: plot(iris$Species, iris$Sepal.Length, xlab='Species', ylab='Sepal Length', main='Sepal Variation

Producing a boxplot in ggplot2 using summary statistics

[亡魂溺海] 提交于 2019-12-18 15:37:33
问题 Below is a code for producing a boxplot using ggplot2 I'm trying to modify in order to suit my problem: library(ggplot2) set.seed(1) # create fictitious data a <- rnorm(10) b <- rnorm(12) c <- rnorm(7) d <- rnorm(15) # data groups group <- factor(rep(1:4, c(10, 12, 7, 15))) # dataframe mydata <- data.frame(c(a,b,c,d), group) names(mydata) <- c("value", "group") # function for computing mean, DS, max and min values min.mean.sd.max <- function(x) { r <- c(min(x), mean(x) - sd(x), mean(x), mean

Producing a boxplot in ggplot2 using summary statistics

两盒软妹~` 提交于 2019-12-18 15:37:09
问题 Below is a code for producing a boxplot using ggplot2 I'm trying to modify in order to suit my problem: library(ggplot2) set.seed(1) # create fictitious data a <- rnorm(10) b <- rnorm(12) c <- rnorm(7) d <- rnorm(15) # data groups group <- factor(rep(1:4, c(10, 12, 7, 15))) # dataframe mydata <- data.frame(c(a,b,c,d), group) names(mydata) <- c("value", "group") # function for computing mean, DS, max and min values min.mean.sd.max <- function(x) { r <- c(min(x), mean(x) - sd(x), mean(x), mean

R boxplot: How to customize the appearance of the box-and-whisker plots (e.g., remove lines or borders, change symbol of outliers)

戏子无情 提交于 2019-12-18 10:19:42
问题 Today, I was wondering how to customize the appearance of the box-and-whisker plots. E.g., I wanted to remove the line around the box. However, the problem is, that the border argument changes the color of all lines of the box-and-whisker plots simultaneously. So, if one has the great idea to set border = "white" then the whiskers are also going to “disappear” and you have a white line representing your median. As I could not find a solution on the internet dealing with exactly my problem, I

Matplotlib Boxplot: Showing Number of Occurrences of Integer Outliers

倾然丶 夕夏残阳落幕 提交于 2019-12-18 09:13:33
问题 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? 回答1: 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

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

拥有回忆 提交于 2019-12-18 07:24:20
问题 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"

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

萝らか妹 提交于 2019-12-18 07:23:21
问题 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,

Boxplot in R showing the mean

若如初见. 提交于 2019-12-17 22:34:10
问题 Does anybody know of a way of generating a boxplot in R with a line (or another symbol) in the value corresponding to the mean? Thank you! 回答1: abline(h=mean(x)) for a horizontal line (use v instead of h for vertical if you orient your boxplot horizontally), or points(mean(x)) for a point. Use the parameter pch to change the symbol. You may want to colour them to improve visibility too. Note that these are called after you have drawn the boxplot. If you are using the formula interface, you