Last active
March 12, 2016 21:39
-
-
Save infotroph/93a45d8d54da5ad74696 to your computer and use it in GitHub Desktop.
Just getting some bad aesthetic decisions out of my system while working out how to do a different thing. Might be "useful" for teaching ggplot themes?
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
anycolors = function(n)rgb(runif(n), runif(n), runif(n)) | |
color_grid = function(x, y, nx=10, ny=nx){ | |
g = expand.grid( | |
x=seq(min(x), max(x), by=diff(range(x))/nx), | |
y=seq(min(y), max(y), by=diff(range(y))/ny)) | |
g$color = anycolors(nrow(g)) | |
g | |
} | |
theme_clownbarf = function(base_size=18, base_family=""){ | |
theme_bw(base_size=18, base_family="") %+% theme( | |
text=element_text( | |
size=base_size, | |
family=base_family, | |
color=anycolors(20)), | |
line=element_line( | |
size=rel(1.5), | |
color=anycolors(20)), | |
panel.border=element_rect( | |
size=2, | |
color=anycolors(1)), | |
axis.ticks=element_line(color=anycolors(50)), | |
legend.background=element_rect(fill=anycolors(1)), | |
legend.key=element_rect(fill=anycolors(10)), | |
aspect.ratio=0.75, | |
panel.grid.major=element_blank(), | |
panel.grid.minor=element_blank() | |
) | |
} | |
(ggplot(mtcars, aes(wt, mpg, color=factor(cyl))) | |
+geom_tile( | |
data=color_grid(mtcars$wt, mtcars$mpg), | |
aes(x=x, y=y, fill=color), | |
color=0, | |
alpha=0.3, | |
position="jitter", | |
show.legend=FALSE) | |
+geom_point(size=8) | |
+xlab("Vehicle weight") | |
+ylab("Miles per gallon") | |
+scale_color_manual(values=rainbow(7)) | |
+theme_clownbarf(18, "Zapfino") | |
+theme(legend.position=c(0.8, 0.75))) |
Author
infotroph
commented
Mar 12, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment