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:
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.
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)
}
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)
}
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
)
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With