Skip to content

Instantly share code, notes, and snippets.

@fdschneider
Created March 15, 2018 16:36
Show Gist options
  • Save fdschneider/fe83561e4ed5afde01ef5b2b7cd132ef to your computer and use it in GitHub Desktop.
Save fdschneider/fe83561e4ed5afde01ef5b2b7cd132ef to your computer and use it in GitHub Desktop.
plot_palette <- function(v) {
pardefault <- par()
call <- format(substitute(v))
n <- length(v)
par(mar = c(0,0,0,0)+0.05, bty = "n")
plot(NA,NA, type = "n", xaxt = "n", yaxt = "n", xlim = c(0,1), ylim = c(0,1),
asp =1/10)
rect(xleft = seq(0,1,1/n)[1:n],
ybottom = c(0,0,0,0),
xright = seq(0,1,1/n)[1:n+1],
ytop = c(1,1,1,1),
col = v[1:n],
border = NA
)
mtext(call, line = -3)
text(seq(0,1,1/n)[1:n]+(1/n/2),0.5, labels = v[1:n], cex = 0.8 )
#par(pardefault)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment