File:R-US state areas-boxplot sqrt+extras.svg
Description |
English: Horizontal boxplot example with square-root-transformed continuous data, outliers identified by name and both log & linear axes plotted. Data = US state areas |
||
Date | |||
Source | Own work | ||
Author | HYanWong | ||
Permission (Reusing this file) |
|
||
SVG development | |||
Source code | R codesvg(file = "R-US_state_areas-boxplot_sqrt+extras.svg", width = 5, height = 1.5, pointsize = 8)
#Horizontal boxplot example with square-root-transformed continuous data, outliers identified by name and both log & linear axes plotted. Data = US state areas
par(mar=c(3,4,4,1)+0.1)
X <- sqrt(state.area*2.58998811)
stripchart(X, pch=NA, xlim=c(0,max(X)), xlab=expression(sqrt(italic("landArea"))), mgp=c(2,0.5,0))
bp <- boxplot(X, horizontal=TRUE, add=TRUE, xaxt="n")
axis(3,sqrt(10^5*0:20),10^2*0:20, cex.axis=0.8, mgp=c(2.5,0.4,0), las=3, tcl=-0.2)
mtext(expression(italic("LandArea")), 3, line=2, adj=-0.11, cex=0.8)
mtext(expression(paste("(1000s of km"^2, ")", sep="")), 3, line=1.2, adj=-0.15, cex=0.8)
abline(v=sqrt(10^5*0:20), lty="dotted", col="lightgray")
title(main="Size of US states", line=2.5)
###Label outliers
outliers <- order(match(X, sort(boxplot.stats(X)$out)), na.last=NA)
odd <- c(TRUE, FALSE)
text(X[outliers[odd]], 1, labels=state.name[outliers[odd]], adj=-0.2, cex=0.65, srt=45, xpd=NA, col="grey40")
text(X[outliers[!odd]], 1, labels=state.name[outliers[!odd]], adj=1.2, cex=0.65, srt=45, xpd=NA, col="grey40")
dev.off()
|