Skip to content

Instantly share code, notes, and snippets.

@earino
Last active August 29, 2015 14:19
Show Gist options
  • Save earino/e2adbc3931196e0b749c to your computer and use it in GitHub Desktop.
Save earino/e2adbc3931196e0b749c to your computer and use it in GitHub Desktop.
plot.R
p <- ggplot(data.frame(x=c(2,4,8,16), y=c(1, 1.84, 3.7, 7.22)), aes(x=x, y=y)) +
ggtitle("Scaling of Spark Decision Trees") +
xlab("Machines") +
ylab("Speedup") +
geom_line(aes(color="actual")) +
geom_point() +
geom_text(aes(label=y), vjust=.5, hjust=-.15) +
geom_line(aes(y=2*y, color="implied")) +
geom_point(aes(y=2*y)) +
geom_text(aes(y=2*y, label=2*y), vjust=1.4) +
geom_line(aes(x=a, y=b, color="ideal"),
data=data.frame(a = c(2,16), b = c(2,16))) +
geom_point(aes(x=a, y=b),
data=data.frame(a = c(4,8,16), b = c(4,8,16))) +
geom_text(aes(label=b, x=a, y=b),
data=data.frame(a = c(4,8,16), b = c(4,8,16)), vjust=-1) +
geom_text(aes(label="actual", x=12, y=5.85, angle=24)) +
geom_text(aes(label="implied", x=12.5, y=11.8, angle=41)) +
geom_text(aes(label="ideal",
x=12, y=12.5, angle=45)) +
geom_segment(aes(x=15, y=10.6, xend=15, yend=13.25), arrow=arrow()) +
geom_text(aes(x=15, y=10.25, label="???")) +
geom_segment(aes(x=15, y=9.9, xend=15, yend=7), arrow=arrow()) +
scale_x_continuous(limits=c(1,16), breaks=c(2,4,8,16)) +
scale_y_continuous(limits=c(1,16), breaks=c(2,3.68,4,6,7.4,8,14.44,16),
labels=c(2,"",4,6,"",8,"",16)) +
scale_colour_manual(name="", values=c("ideal"="darkgreen", "actual"="red", "implied"="blue")) +
theme_fivethirtyeight() + coord_fixed()
gt <- ggplot_gtable(ggplot_build(p))
gt$layout$clip[gt$layout$name == "panel"] <- "off"
grid.draw(gt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment