Created
October 17, 2012 22:41
-
-
Save emhart/3908799 to your computer and use it in GitHub Desktop.
ggplot options
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
### Set-up theme | |
theme_popblk = function(size=12) { | |
o = list( | |
#axis.line=theme_blank(), | |
axis.text.x=theme_text(size=size*.9), | |
axis.text.y=theme_text(size=size*.9), | |
# axis.text.y=theme_blank(), | |
# axis.ticks.y=theme_blank(), | |
# axis.ticks=theme_blank(), | |
axis.ticks.length=unit(0.3, "lines"), | |
axis.ticks.margin=unit(0.5, "lines"), | |
axis.title.x=theme_text(size=size*1), | |
axis.title.y=theme_text(size=size*1,angle=90), | |
# legend.background=theme_rect(fill="white", colour=NA), | |
legend.key=theme_rect(colour="white"), | |
legend.key.size=unit(1.2, "lines"), | |
# legend.position="right", | |
legend.text=theme_text(size=size), | |
legend.title=theme_text(size=size, face="bold", | |
hjust=0), | |
panel.background=theme_rect(fill="white",colour="black"), | |
# panel.border=theme_blank(), | |
# panel.grid.major=theme_line(colour="gray70"), | |
panel.grid.major=theme_blank(), | |
panel.grid.minor=theme_blank(), | |
panel.margin=unit(0, "lines"), | |
plot.background=theme_blank(), | |
plot.margin=unit(c(1, 1, 0.5, 0.5), "lines"), | |
plot.title=theme_text(size=size*1.2), | |
strip.background=theme_rect(fill="grey90", | |
colour="black"), | |
strip.text.x=theme_text(size=size*1) ) | |
# strip.text.y=theme_text(size=size*1, angle=-90)) | |
return(structure(o, class="options")) } | |
###### Minimal example taken from ggplot docs ##### | |
df <- data.frame( | |
trt = factor(c(1, 1, 2, 2)), | |
resp = c(1, 5, 3, 4), | |
group = factor(c(1, 2, 1, 2)), | |
se = c(0.1, 0.3, 0.3, 0.2) | |
) | |
df2 <- df[c(1,3),] | |
p <- ggplot(df, aes(fill=group, y=resp, x=trt)) | |
p + geom_bar(position="dodge", stat="identity") | |
#### By adding theme, background color should be stripped, fonts changed, etc... worked before ggplot update | |
p + geom_bar(position="dodge", stat="identity") + theme_popblk() | |
### however the following error is generated #### | |
# > p + geom_bar(position="dodge", stat="identity") + theme_popblk() | |
# Error: Don't know how to add o to a plot | |
# In addition: There were 14 warnings (use warnings() to see them) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like you can modify themes easily too by
%+replace%
, e.g., in hadley's documentation: