Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

plot - Plotting Quantiles values of boxplot in R inside a for loop

Suppose I have a data frame airquality. I made a for loop to plot all the boxplot of the air-quality data set.

name <- names(airquality)

classes<-sapply(airquality,class)

airquality[is.na(airquality)] <- 0

for (name in name[classes == 'numeric']) {
  boxplot(airquality[,name])
}

Now I want to display all the Quantiles values i.e. First Quantile, Median, Third Quantile and mean as in the below image. I searched the web a lot but didn't find anything that suits my need. Below is the desired graph which I want to plot:

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here is an example, just using the "Wind" attribute.

B = boxplot(airquality[,"Wind"])
text(1.3, B$stats, B$stats)

IQR = B$stats[4] - B$stats[2]
segments(0.5, c(B$stats[2], B$stats[4]), 0.7, c(B$stats[2], B$stats[4]))
text(0.6, B$stats[3], IQR)
arrows(0.6, B$stats[3]+0.5, 0.6, B$stats[4]-0.1, 0.1)
arrows(0.6, B$stats[3]-0.5, 0.6, B$stats[2]+0.1, 0.1)

Boxplot of wind


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...