-
-
Save jrherr/6568d208103897923483 to your computer and use it in GitHub Desktop.
R code to create Excel-like barplot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x <- data.frame(d=runif(12), g=rep(1:4, each =3)) | |
my.col <- c("deepskyblue3","darkorange2","darkgray","gold") | |
spacer <- c(1, 0.1, 0.1, 1, 0.1, 0.1, 1, 0.1, 0.1, 1, 0.1, 0.1) | |
bw <- 0.8 | |
xmax <- (sum(spacer) * bw) + (nrow(x) * bw) | |
barplot(x$d, col=my.col[x$g], yaxt="n", xaxt="n", width=bw, xlim=c(0,15), space=spacer, border=NA) | |
axis(side=2, at=seq(0,1,by=0.1), labels=TRUE, tick=FALSE, lwd=0, las=2, cex.axis=0.8) | |
midbar <- function(x) { | |
pos <- (sum(spacer[1:x]) * bw) + (bw * x) - (bw/2) | |
return(pos) | |
} | |
xtks <- apply(array(c(2,5,8,11)),1,midbar) | |
axis(side=1, at=xtks, labels=1:4, tick=TRUE, lwd=0) | |
for (h in seq(0.1,0.9,by=0.1)) { | |
lines(c(0,xmax+1), c(h,h)) | |
} | |
barplot(x$d, col=my.col[x$g], yaxt="n", xaxt="n", width=bw, xlim=c(0,15), space=spacer, add=TRUE, border=NA, main="IFL Excel") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment