Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recreate Tufte Moiré vibration

Tags:

plot

r

Tufte gives a good bad example of why cross hatching is distorting, the shimmer effect (The Visual Display of Quantitative Information, 2001, p. 108) that looks similar to:

enter image description here

Though his is crisper. How could I replicate this in R? As it's not considered good practice figuring out the easiest way to replicate is proving challenging.

like image 207
Tyler Rinker Avatar asked Mar 10 '15 22:03

Tyler Rinker


3 Answers

Here's an option using abline:

plot(NA,NA, xlim=c(0,100), ylim=c(0,100))
for(i in seq(-15,600,6)) {
  abline(i, -3, lwd=6)
}

enter image description here

Edit per Tyler: Here's what I used exactly in a knitr doc, just as annoying as the original.

plot(NA,NA, xlim=c(0,100), ylim=c(0,100), ylab=NA, xlab=NA, yaxt='n', xaxt='n', bty = "n")
for(i in seq(-15,500,6)) {
  abline(i, -3, lwd=4)
}
like image 143
eipi10 Avatar answered Oct 04 '22 04:10

eipi10


polygon to the rescue:

plot(0:1,type="n")
polygon(
  x=c(1,1,2,2),
  y=c(1,0,0,1),
  density=10,
  angle=135,
  lwd=5, 
  border=NA
)

enter image description here

like image 34
thelatemail Avatar answered Oct 04 '22 05:10

thelatemail


For completeness, here's a ggplot2 solution, as always the challenge is getting the underlying data right...

hatch <- function(xsequence, ysequence, weight = 1) {
  require(ggplot2) 
  df <- data.frame(x = c(rep(0, length(ysequence)),xsequence, xsequence, rep(max(xsequence), length(ysequence))),
                   y = c(ysequence, rep(max(ysequence), length(xsequence)), rep(0, length(xsequence)), ysequence), 
                   group = seq_along(1:(length(xsequence) + length(ysequence))))
  p <- ggplot(df, aes(x, y)) + geom_line(aes(group = group), size = weight)
  print(p + theme(panel.background = element_rect(fill = "transparent"),
                  axis.text = element_blank(),
                  axis.ticks = element_blank(),
                  axis.title = element_blank()))

}
hatch(1:100, 1:40, 1.5)

enter image description here

like image 20
alexwhan Avatar answered Oct 04 '22 05:10

alexwhan