Skip to content
{{ message }}

Instantly share code, notes, and snippets.

# benmarwick/gist:8cf22ecb74ac511f8ac1c70aef6038a7

Last active Nov 2, 2021
How to make diamond plots after Bergstrom and West (2018) "Why scatter plots suggest causality, and what we can do about it"
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
 # https://arxiv.org/pdf/1809.09328.pdf & https://twitter.com/CT_Bergstrom/status/1035327464644333568 # they use Mathematica, boo! So let's make them with R # starting with https://stackoverflow.com/q/33396168/1036500 library(ggplot2) p <- ggplot() + geom_point(data = anscombe, aes(x = x1, y = y1), colour = "red", alpha = 0.5, size = 3) + theme_minimal() + theme(axis.text.x= element_text(size = 10), axis.text.y= element_text(size = 10)) + theme(axis.text.x = element_text(angle=(-1 * rotation)), axis.text.y = element_text(angle=(-1 * rotation)), axis.title.x = element_text(size = 12, angle=(-1 * rotation), vjust = 0.5, margin = margin(t = 10), colour = "red"), axis.title.y = element_text(size = 12, angle=(-1 * rotation), hjust = 0.5, margin = margin(r = 20), colour = "red")) + coord_equal() + scale_x_continuous(limits = c(0, 15), name = "x") + scale_y_continuous(limits = c(0, 15), name = "y") library(grid) print(p, vp=viewport(angle=rotation, width = unit(.75, "npc"), height = unit(.75, "npc")))

### benmarwick commented Mar 21, 2019

 How to draw a diamond plot visualization with R and ggplot2
to join this conversation on GitHub. Already have an account? Sign in to comment