hadley/ggplot2 — pull request #693 by jrnold (2012-10-14 20:57:24+00:00)
Title: improved print methods for theme and element classes

I added new print methods for `theme` and `element` objects which are easier to understand than the existing methods. Additionally, the output of print can be evaluated to recreate the object. This makes it easy to create a new theme by printing an existing theme and making edits to the output.

Example of print output for `theme_gray`

``` r-console
> print(theme_gray()$rect)
element(fill = "white", colour = "black", size = 0.5, linetype = 1)
> print(theme_gray())
theme(line = element(colour = "black", size = 0.5, linetype = 1, lineend = "butt"),
rect = element(fill = "white", colour = "black", size = 0.5, linetype = 1),
text = element(family = "", face = "plain", colour = "black", size = 12, hjust = 0.5, vjust = 0.5, angle = 0, lineheight = 0.9),
axis.text = element(colour = "grey50", size = rel(0.8)),
strip.text = element(size = rel(0.8)),
axis.line = element(),
axis.text.x = element(vjust = 1),
axis.text.y = element(hjust = 1),
axis.ticks = element(colour = "grey50"),
axis.title.x = element(),
axis.title.y = element(angle = 90),
axis.ticks.length = unit(0.15, "cm"),
axis.ticks.margin = unit(0.1, "cm"),
legend.background = element(colour = NA),
legend.margin = unit(0.2, "cm"),
legend.key = element(fill = "grey95", colour = "white"),
legend.key.size = unit(1.2, "lines"),
legend.key.height = NULL,
legend.key.width = NULL,
legend.text = element(size = rel(0.8)),
legend.text.align = NULL,
legend.title = element(face = "bold", size = rel(0.8), hjust = 0),
legend.title.align = NULL,
legend.position = "right",
legend.direction = NULL,
legend.justification = "center",
legend.box = NULL,
panel.background = element(fill = "grey90", colour = NA),
panel.border = element(),
panel.grid.major = element(colour = "white"),
panel.grid.minor = element(colour = "grey95", size = 0.25),
panel.margin = unit(0.25, "lines"),
strip.background = element(fill = "grey80", colour = NA),
strip.text.x = element(),
strip.text.y = element(angle = -90),
plot.background = element(colour = "white"),
plot.title = element(size = rel(1.2)),
plot.margin = unit(c(1, 1, 0.5, 0.5), "lines"),
complete = TRUE)
```

The print output evaluates to the original object.

``` r-console
> identical(eval(parse(text=as.character(theme_gray()))), theme_gray())
TRUE
```