Hello, all, I have a dataframe of three rows and umpteen columns. I want to show the maximum, minimum, and median with a vertical line and a central dot (I'd use a boxplot, but with only three data points, that's overkill; I can't just use points, because of overlap and some of the other data plotted on the graph). This works:> boxplot(data_frame, col="transparent", border="dark grey", xaxt="n",add=TRUE) But these don't:> st <- c(1:19) > segments(st, pmax(data_frame), st, pmin(data_frame))(no, I haven't tried to put in the median points yet) I can plot them individually with> segments(1, max(data_frame[,1]), 1, pmin(data_frame[,1])) > points(1, median(fly_ash[,1]))but that's a bit tedious. Is there a better way of vectorising these columns such that they will work with pmax? Is there something like a pmedian? Regards, Hazel Jenkins
Gabor Grothendieck
2008-Apr-27 17:19 UTC
[R] parallel max, min, and median of dataframe columns
One can use sapply(data_frame, min) and similarly for max and median. Another possibility is to use quantile and matplot like this ir <- iris[1:3, 1:4] # sample data using builtin iris data set mat <- t(sapply(ir, quantile, c(1, .5, 0))) matplot(mat, type = "hp", lty = 1, pch = 20, xaxt = "n", col = c("black", "red", "white")) axis(1, seq_along(ir)) # or maybe axis(1, seq_along(ir), names(ir)) On Sun, Apr 27, 2008 at 12:25 PM, H.Jenkins <hjenkins at uvic.ca> wrote:> Hello, all, > > I have a dataframe of three rows and umpteen columns. I want to show the > maximum, minimum, and median with a vertical line and a central dot (I'd > use a boxplot, but with only three data points, that's overkill; I can't > just use points, because of overlap and some of the other data plotted on > the graph). > > This works: > > boxplot(data_frame, col="transparent", border="dark grey", xaxt="n", > add=TRUE) > > But these don't: > > st <- c(1:19) > > segments(st, pmax(data_frame), st, pmin(data_frame)) > > (no, I haven't tried to put in the median points yet) > > I can plot them individually with > > segments(1, max(data_frame[,1]), 1, pmin(data_frame[,1])) > > points(1, median(fly_ash[,1])) > but that's a bit tedious. Is there a better way of vectorising these > columns such that they will work with pmax? Is there something like a > pmedian? > > Regards, > Hazel Jenkins > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >