Skip to content

Commit

Permalink
Update vignettes; delete part that doesn't work anymore.
Browse files Browse the repository at this point in the history
  • Loading branch information
clauswilke committed Mar 6, 2016
1 parent 81687f3 commit ba1f511
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 60 deletions.
6 changes: 3 additions & 3 deletions inst/doc/introduction.html

Large diffs are not rendered by default.

15 changes: 0 additions & 15 deletions inst/doc/plot_grid.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,6 @@ plot.iris <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
plot_grid(plot.iris, plot.mpg, labels = "AUTO", ncol = 1,
align = 'v') # aligning does not work here

## ---- message=FALSE, fig.width=4.25, fig.height=5.1----------------------
require(grid) # for unit.pmax()
g.iris <- ggplotGrob(plot.iris) # convert to gtable
g.mpg <- ggplotGrob(plot.mpg) # convert to gtable

iris.widths <- g.iris$widths[1:3] # extract the first three widths,
# corresponding to left margin, y lab, and y axis
mpg.widths <- g.mpg$widths[1:3] # same for mpg plot
max.widths <- unit.pmax(iris.widths, mpg.widths) # calculate maximum widths
g.iris$widths[1:3] <- max.widths # assign max. widths to iris gtable
g.mpg$widths[1:3] <- max.widths # assign max widths to mpg gtable

# plot_grid() can work directly with gtables, so this works
plot_grid(g.iris, g.mpg, labels = "AUTO", ncol = 1)

## ---- message=FALSE, fig.width=6.8, fig.height=2.55----------------------
plot_grid(plot.mpg, plot.diamonds, labels = "AUTO", align = 'h', label_size = 12)

Expand Down
19 changes: 0 additions & 19 deletions inst/doc/plot_grid.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,6 @@ plot_grid(plot.iris, plot.mpg, labels = "AUTO", ncol = 1,
align = 'v') # aligning does not work here
```

In cases where `plot_grid()` cannot automatcially align plots, you can still align them manually if you have some knowledge of gtable, the internal layouting mechanism used by ggplot2. You simply have to convert both graphs into gtable objects and then adjust the relevant widths or heights. For the plot from the previous example, for example, you could do the following:
```{r, message=FALSE, fig.width=4.25, fig.height=5.1}
require(grid) # for unit.pmax()
g.iris <- ggplotGrob(plot.iris) # convert to gtable
g.mpg <- ggplotGrob(plot.mpg) # convert to gtable
iris.widths <- g.iris$widths[1:3] # extract the first three widths,
# corresponding to left margin, y lab, and y axis
mpg.widths <- g.mpg$widths[1:3] # same for mpg plot
max.widths <- unit.pmax(iris.widths, mpg.widths) # calculate maximum widths
g.iris$widths[1:3] <- max.widths # assign max. widths to iris gtable
g.mpg$widths[1:3] <- max.widths # assign max widths to mpg gtable
# plot_grid() can work directly with gtables, so this works
plot_grid(g.iris, g.mpg, labels = "AUTO", ncol = 1)
```

Notice how now the y axes in plots A and B are located at exactly the same horizontal position.

# Fine-tuning the plot appearance

You can adjust the label size via the `label_size` option. Default is 14, so larger values will make the labels larger and smaller values will make them smaller:
Expand Down
16 changes: 0 additions & 16 deletions inst/doc/plot_grid.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/doc/shared_legends.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ legend_b <- grobs[[which(sapply(grobs, function(x) x$name) == "guide-box")]]

# add the legend underneath the row we made earlier. Give it 10% of the height
# of one plot (via rel_heights).
p <- plot_grid( prow, legend_b, ncol = 1, rel_heights = c(1, .1))
p <- plot_grid( prow, legend_b, ncol = 1, rel_heights = c(1, .2))
p

## ----fig.width=10, fig.height=3------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion inst/doc/shared_legends.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ legend_b <- grobs[[which(sapply(grobs, function(x) x$name) == "guide-box")]]
# add the legend underneath the row we made earlier. Give it 10% of the height
# of one plot (via rel_heights).
p <- plot_grid( prow, legend_b, ncol = 1, rel_heights = c(1, .1))
p <- plot_grid( prow, legend_b, ncol = 1, rel_heights = c(1, .2))
p
```

Expand Down
10 changes: 5 additions & 5 deletions inst/doc/shared_legends.html

Large diffs are not rendered by default.

0 comments on commit ba1f511

Please sign in to comment.