diff --git a/docs/404.html b/docs/404.html index 7d5bbbd..6cb5599 100644 --- a/docs/404.html +++ b/docs/404.html @@ -1,74 +1,34 @@ - - - - + + + + - Page not found (404) • cowplot - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + - - - - -
-
- + +
+ + + - - -
+
+
-
+ + - - diff --git a/docs/ISSUE_TEMPLATE.html b/docs/ISSUE_TEMPLATE.html index 3480469..bbc9a53 100644 --- a/docs/ISSUE_TEMPLATE.html +++ b/docs/ISSUE_TEMPLATE.html @@ -1,74 +1,12 @@ - - - - - - - -NA • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -NA • cowplot - + + - - - -
-
- -
- -
+
-

Issues are meant to report bugs or request features. If you have questions about how to correctly use this package, please don’t use the issue system. Such questions can be asked on stackoverflow https://stackoverflow.com/ or the RStudio community https://community.rstudio.com/. If you are not sure where to go, please try https://stackoverflow.com/ first.

-

Issues must contain reproducible code examples. Please use the reprex package to create your example (see here: http://reprex.tidyverse.org/). Issues without reprex may be closed without comment.

+

Issues are meant to report bugs or request features. If you have questions about how to correctly use this package, please don’t use the issue system. Such questions can be asked on stackoverflow https://stackoverflow.com/ or the RStudio community https://community.rstudio.com/. If you are not sure where to go, please try https://stackoverflow.com/ first.

+

Issues must contain reproducible code examples. Please use the reprex package to create your example (see here: http://reprex.tidyverse.org/). Issues without reprex may be closed without comment.

Please delete these instructions after you have read them.

-
-

Brief description of the problem or desired feature.

-
# insert reprex here
+

Brief description of the problem or desired feature.

+

{r} # insert reprex here

+
-
- - + + diff --git a/docs/articles/aligning_plots.html b/docs/articles/aligning_plots.html index 4c0e047..b752b36 100644 --- a/docs/articles/aligning_plots.html +++ b/docs/articles/aligning_plots.html @@ -26,6 +26,8 @@ + +
+
-

There are several packages that can be used to align plots. The most widely used ones beside cowplot are egg and patchwork. All these packages use slightly different approaches to plot alignment, and the respective approaches have different strengths and weaknesses. If you cannot achieve your desired result with one of these packages try another one.

-

Most importantly, while egg and patchwork align and arrange plots at the same time, cowplot aligns plots independently of how they are arranged. This makes it possible to align plots and then reproduce them separately, or even overlay them on top of each other.

-

We’ll start with a very simple example. Let’s consider these two plots.

-
-library(ggplot2)
-library(cowplot)
-
-p1 <- ggplot(mtcars, aes(disp, mpg)) + 
-  geom_point()
-p2 <- ggplot(mtcars, aes(disp, hp)) + 
-  geom_point()
-p1
-
+

There are several packages that can be used to align plots. The most +widely used ones beside cowplot are egg and patchwork. All these +packages use slightly different approaches to plot alignment, and the +respective approaches have different strengths and weaknesses. If you +cannot achieve your desired result with one of these packages try +another one.

+

Most importantly, while egg and patchwork align and arrange plots at +the same time, cowplot aligns plots independently of how they are +arranged. This makes it possible to align plots and then reproduce them +separately, or even overlay them on top of each other.

+

We’ll start with a very simple example. Let’s consider these two +plots.

+
+library(ggplot2)
+library(cowplot)
+
+p1 <- ggplot(mtcars, aes(disp, mpg)) + 
+  geom_point()
+p2 <- ggplot(mtcars, aes(disp, hp)) + 
+  geom_point()
+p1

-
-p2
-
+
+p2

-

Both plots have the same x axis, but the width of the plot area is slightly larger in the first than in the second, because the y axis labels have different lengths. These differences in plot width could be distracting in a document where both plots are shown near each other. We can fix this problem by vertically aligning the two plots and then drawing them individually.

-
-aligned <- align_plots(p1, p2, align = "v")
-ggdraw(aligned[[1]])
-
+

Both plots have the same x axis, but the width of the plot area is +slightly larger in the first than in the second, because the y axis +labels have different lengths. These differences in plot width could be +distracting in a document where both plots are shown near each other. We +can fix this problem by vertically aligning the two plots and then +drawing them individually.

+
+aligned <- align_plots(p1, p2, align = "v")
+ggdraw(aligned[[1]])

-
-ggdraw(aligned[[2]])
-
+
+ggdraw(aligned[[2]])

-

Vertical alignment (align = "v") means that any vertical reference lines, such as the right and left y axis lines, are aligned in the plots. By contrast, horizontal alignment (align = "h") aligns horizontal reference lines. Both types of alignment can be used separately (align = "v" or align = "h") or in combination (align = "vh" or align = "hv").

-

If we want to align and then arrange plots, we can call plot_grid() and provide it with an align argument. The plot_grid() function calls align_plots() to align the plots and then arranges them.

-
-plot_grid(p1, p2, ncol = 1, align = "v")
-
+

Vertical alignment (align = "v") means that any vertical +reference lines, such as the right and left y axis lines, are aligned in +the plots. By contrast, horizontal alignment (align = "h") +aligns horizontal reference lines. Both types of alignment can be used +separately (align = "v" or align = "h") or in +combination (align = "vh" or +align = "hv").

+

If we want to align and then arrange plots, we can call +plot_grid() and provide it with an align +argument. The plot_grid() function calls +align_plots() to align the plots and then arranges +them.

+
+plot_grid(p1, p2, ncol = 1, align = "v")

-
-

-Aligning by axis

-

The vertical and horizontal alignment as described above tries to align every vertical or horizontal element in all plots. In other words, the axis titles are aligned to each other, the axis ticks are aligned to each other, the plot panels are aligned to each other, and so on. This method of alignment only works if all plots have exactly the same elements. Therefore, it fails, for example, if we try to align a plot that is faceted with one that is not.

-
-p1 <- ggplot(mtcars, aes(disp, mpg)) + 
-  geom_point() +
-  theme_minimal_grid(14) + 
-  panel_border(color = "black")
-
-p2 <- ggplot(mtcars, aes(factor(vs))) + 
-  geom_bar() + 
-  facet_wrap(~am) +
-  scale_y_continuous(expand = expansion(mult = c(0, 0.1))) +
-  theme_minimal_hgrid(12) +
-  panel_border(color = "black") +
-  theme(strip.background = element_rect(fill = "gray80"))
-
-plot_grid(p1, p2, align = "h", rel_widths = c(1, 1.3))
-
-
## Warning: Graphs cannot be horizontally aligned unless the axis parameter is set.
-## Placing graphs unaligned.
+
+

Aligning by axis +

+

The vertical and horizontal alignment as described above tries to +align every vertical or horizontal element in all plots. In other words, +the axis titles are aligned to each other, the axis ticks are aligned to +each other, the plot panels are aligned to each other, and so on. This +method of alignment only works if all plots have exactly the same +elements. Therefore, it fails, for example, if we try to align a plot +that is faceted with one that is not.

+
+p1 <- ggplot(mtcars, aes(disp, mpg)) + 
+  geom_point() +
+  theme_minimal_grid(14) + 
+  panel_border(color = "black")
+
+p2 <- ggplot(mtcars, aes(factor(vs))) + 
+  geom_bar() + 
+  facet_wrap(~am) +
+  scale_y_continuous(expand = expansion(mult = c(0, 0.1))) +
+  theme_minimal_hgrid(12) +
+  panel_border(color = "black") +
+  theme(strip.background = element_rect(fill = "gray80"))
+
+plot_grid(p1, p2, align = "h", rel_widths = c(1, 1.3))
+
## Warning: Graphs cannot be horizontally aligned unless the axis parameter is
+## set. Placing graphs unaligned.

-

We receive a warning that the plots cannot be aligned, and the plots are drawn without alignment. To align these plots, we need to tell the align_plots() function which parts of the plots should be aligned. There are two alternatives, and both can be meaningful. First, we can align only the bottom axis (axis = "b").

-
-plot_grid(p1, p2, align = "h", axis = "b", rel_widths = c(1, 1.3))
-
+

We receive a warning that the plots cannot be aligned, and the plots +are drawn without alignment. To align these plots, we need to tell the +align_plots() function which parts of the plots should be +aligned. There are two alternatives, and both can be meaningful. First, +we can align only the bottom axis (axis = "b").

+
+plot_grid(p1, p2, align = "h", axis = "b", rel_widths = c(1, 1.3))

-

Second, we can align both the bottom and the top axis (axis = "bt").

-
-plot_grid(p1, p2, align = "h", axis = "bt", rel_widths = c(1, 1.3))
-
+

Second, we can align both the bottom and the top axis +(axis = "bt").

+
+plot_grid(p1, p2, align = "h", axis = "bt", rel_widths = c(1, 1.3))

-

In general, the axis argument tells the align_plots() function to only align specific axes. It understands the values "t" (top), "r" (right), "b" (bottom), and "l" (left), in any combination.

-

As a second example, I will show how aligning by axis can be useful even if the plots contain the same number of elements. Consider this vertical arrangement of two plots, showing first the number of cars in different classes in the mpg dataset and second a scatter plot of the mean city mpg for each class versus the number of cars in the class.

-
-library(dplyr)
-library(forcats)
-
-city_mpg <- mpg %>%
-  mutate(class = fct_lump(class, 4, other_level = "other")) %>%
-  group_by(class) %>%
-  summarize(
-    mean_mpg = mean(cty),
-    count = n()
-  ) %>% mutate(
-    class = fct_reorder(class, count)
-  )
-
-
-p1 <- ggplot(city_mpg, aes(class, count)) + 
-  geom_col() + 
-  ylim(0, 65) + 
-  coord_flip()
-
-p2 <- ggplot(city_mpg, aes(mean_mpg, count)) + 
-  geom_point()
-
-plot_grid(p1, p2, ncol = 1, align = 'v')
-
+

In general, the axis argument tells the +align_plots() function to only align specific axes. It +understands the values "t" (top), "r" (right), +"b" (bottom), and "l" (left), in any +combination.

+

As a second example, I will show how aligning by axis can be useful +even if the plots contain the same number of elements. Consider this +vertical arrangement of two plots, showing first the number of cars in +different classes in the mpg dataset and second a scatter +plot of the mean city mpg for each class versus the number of cars in +the class.

+
+library(dplyr)
+library(forcats)
+
+city_mpg <- mpg %>%
+  mutate(class = fct_lump(class, 4, other_level = "other")) %>%
+  group_by(class) %>%
+  summarize(
+    mean_mpg = mean(cty),
+    count = n()
+  ) %>% mutate(
+    class = fct_reorder(class, count)
+  )
+
+
+p1 <- ggplot(city_mpg, aes(class, count)) + 
+  geom_col() + 
+  ylim(0, 65) + 
+  coord_flip()
+
+p2 <- ggplot(city_mpg, aes(mean_mpg, count)) + 
+  geom_point()
+
+plot_grid(p1, p2, ncol = 1, align = 'v')

-

Because the y axis labels of the first plot are very long, the y axis title of the second plot is located far removed from the axis labels. This looks strange. It would be better to move the axis title closer to the labels. We can do this by aligning by axis. I’m aligning here only the left axis. Aligning the left and the right axis would have produced the same result.

-
-plot_grid(p1, p2, ncol = 1, align = 'v', axis = 'l')
-
+

Because the y axis labels of the first plot are very long, the y axis +title of the second plot is located far removed from the axis labels. +This looks strange. It would be better to move the axis title closer to +the labels. We can do this by aligning by axis. I’m aligning here only +the left axis. Aligning the left and the right axis would have produced +the same result.

+
+plot_grid(p1, p2, ncol = 1, align = 'v', axis = 'l')

-

Finally, I’ll make two separate plots and then draw them on top of each other. First, let’s again draw a bar plot of the number of cars in different classes in the mpg dataset.

-
-city_mpg <- city_mpg %>%
-  mutate(class = fct_reorder(class, -mean_mpg))
-
-p1 <- ggplot(city_mpg, aes(class, count)) +
-  geom_col(fill = "#6297E770") + 
-  scale_y_continuous(
-    expand = expansion(mult = c(0, 0.05)),
-    position = "right"
-  ) +
-  theme_minimal_hgrid(11, rel_small = 1) +
-  theme(
-    panel.grid.major = element_line(color = "#6297E770"),
-    axis.line.x = element_blank(),
-    axis.text.x = element_blank(),
-    axis.title.x = element_blank(),
-    axis.ticks = element_blank(),
-    axis.ticks.length = grid::unit(0, "pt"),
-    axis.text.y = element_text(color = "#6297E7"),
-    axis.title.y = element_text(color = "#6297E7")
-  )
-p1
-
+

Finally, I’ll make two separate plots and then draw them on top of +each other. First, let’s again draw a bar plot of the number of cars in +different classes in the mpg dataset.

+
+city_mpg <- city_mpg %>%
+  mutate(class = fct_reorder(class, -mean_mpg))
+
+p1 <- ggplot(city_mpg, aes(class, count)) +
+  geom_col(fill = "#6297E770") + 
+  scale_y_continuous(
+    expand = expansion(mult = c(0, 0.05)),
+    position = "right"
+  ) +
+  theme_minimal_hgrid(11, rel_small = 1) +
+  theme(
+    panel.grid.major = element_line(color = "#6297E770"),
+    axis.line.x = element_blank(),
+    axis.text.x = element_blank(),
+    axis.title.x = element_blank(),
+    axis.ticks = element_blank(),
+    axis.ticks.length = grid::unit(0, "pt"),
+    axis.text.y = element_text(color = "#6297E7"),
+    axis.title.y = element_text(color = "#6297E7")
+  )
+p1

Now let’s plot mean city mpg versus car class, as a scatter plot.

-
-p2 <- ggplot(city_mpg, aes(class, mean_mpg)) + 
-  geom_point(size = 3, color = "#D5442D") + 
-  scale_y_continuous(limits = c(10, 21)) +
-  theme_half_open(11, rel_small = 1) +
-  theme(
-    axis.ticks.y = element_line(color = "#BB2D05"),
-    axis.text.y = element_text(color = "#BB2D05"),
-    axis.title.y = element_text(color = "#BB2D05"),
-    axis.line.y = element_line(color = "#BB2D05")
-  )
-p2
-
+
+p2 <- ggplot(city_mpg, aes(class, mean_mpg)) + 
+  geom_point(size = 3, color = "#D5442D") + 
+  scale_y_continuous(limits = c(10, 21)) +
+  theme_half_open(11, rel_small = 1) +
+  theme(
+    axis.ticks.y = element_line(color = "#BB2D05"),
+    axis.text.y = element_text(color = "#BB2D05"),
+    axis.title.y = element_text(color = "#BB2D05"),
+    axis.line.y = element_line(color = "#BB2D05")
+  )
+p2

-

Now we align the two plots and then overlay them. The resulting plot has dual axes, and making such plots is usually discouraged. I present this example here only to show the types of effects we can achieve when plot alignment and plot placement are separated.

-
-aligned_plots <- align_plots(p1, p2, align="hv", axis="tblr")
-ggdraw(aligned_plots[[1]]) + draw_plot(aligned_plots[[2]])
-
+

Now we align the two plots and then overlay them. The resulting plot +has dual axes, and making such plots is usually discouraged. I present +this example here only to show the types of effects we can achieve when +plot alignment and plot placement are separated.

+
+aligned_plots <- align_plots(p1, p2, align="hv", axis="tblr")
+ggdraw(aligned_plots[[1]]) + draw_plot(aligned_plots[[2]])

@@ -279,11 +317,13 @@

-

Site built with pkgdown 1.6.0.

+

+

Site built with pkgdown 2.0.7.

@@ -292,5 +332,7 @@

+ + diff --git a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-10-1.png b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-10-1.png index f33cd84..edf8ce7 100644 Binary files a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-10-1.png and b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-10-1.png differ diff --git a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-11-1.png b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-11-1.png index bbeb60f..62e0eea 100644 Binary files a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-11-1.png and b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-11-1.png differ diff --git a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-12-1.png b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-12-1.png index f27472a..3a43cb7 100644 Binary files a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-12-1.png and b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-12-1.png differ diff --git a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-2-1.png b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-2-1.png index 587884b..6652a8c 100644 Binary files a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-2-1.png and b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-2-1.png differ diff --git a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-2-2.png b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-2-2.png index 9af02fb..7f0358f 100644 Binary files a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-2-2.png and b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-2-2.png differ diff --git a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-3-1.png b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-3-1.png index 9ac7e0c..f694d90 100644 Binary files a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-3-1.png and b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-3-1.png differ diff --git a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-3-2.png b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-3-2.png index 58e86d7..9b1649c 100644 Binary files a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-3-2.png and b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-3-2.png differ diff --git a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-4-1.png index 1061058..ccfe2f3 100644 Binary files a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-4-1.png and b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-5-1.png index 47e762d..556326f 100644 Binary files a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-5-1.png and b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-6-1.png index 61022ef..d21055d 100644 Binary files a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-6-1.png and b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-7-1.png b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-7-1.png index 5a4b3d6..f374b3e 100644 Binary files a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-7-1.png and b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-7-1.png differ diff --git a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-8-1.png b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-8-1.png index 90ed99a..6bac8d6 100644 Binary files a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-8-1.png and b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-8-1.png differ diff --git a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-9-1.png b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-9-1.png index e13e690..94ae97b 100644 Binary files a/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-9-1.png and b/docs/articles/aligning_plots_files/figure-html/unnamed-chunk-9-1.png differ diff --git a/docs/articles/drawing_with_on_plots.html b/docs/articles/drawing_with_on_plots.html index dc16740..c41109b 100644 --- a/docs/articles/drawing_with_on_plots.html +++ b/docs/articles/drawing_with_on_plots.html @@ -26,6 +26,8 @@ + +
+
-

The cowplot package provides functions to draw with and on plots. These functions enable us to take plots and add arbitrary annotations or backgrounds, to place plots inside of other plots, to arrange plots in more complicated layouts, or to combine plots from different graphic systems (ggplot2, grid, lattice, base). This functionality is build on top of ggplot2, i.e., the resulting plots are ggplot2 objects and they can be modified, extended, and outputted just like regular ggplot2 plots.

-
-

-Basic annotations

-

We start with some simple annotations, such as labels or watermarks. Let’s begin with a basic plot of the mpg dataset.

-
-library(ggplot2)
-library(cowplot)
-
-p <- ggplot(mpg, aes(displ, cty)) +
-  geom_point() +
-  theme_minimal_grid(12)
-
-p
-
+

The cowplot package provides functions to draw with and on plots. +These functions enable us to take plots and add arbitrary annotations or +backgrounds, to place plots inside of other plots, to arrange plots in +more complicated layouts, or to combine plots from different graphic +systems (ggplot2, grid, lattice, base). This functionality is build on +top of ggplot2, i.e., the resulting plots are ggplot2 objects and they +can be modified, extended, and outputted just like regular ggplot2 +plots.

+
+

Basic annotations +

+

We start with some simple annotations, such as labels or watermarks. +Let’s begin with a basic plot of the mpg dataset.

+
+library(ggplot2)
+library(cowplot)
+
+p <- ggplot(mpg, aes(displ, cty)) +
+  geom_point() +
+  theme_minimal_grid(12)
+
+p

-

Next we’re going to watermark this plot with the word “Draft”. To do so, we wrap the plot into a drawing environment via the ggdraw() call, and then add annotations via various draw_*() functions.

-
-ggdraw(p) + 
-  draw_label("Draft", color = "#C0A0A0", size = 100, angle = 45)
-
+

Next we’re going to watermark this plot with the word “Draft”. To do +so, we wrap the plot into a drawing environment via the +ggdraw() call, and then add annotations via various +draw_*() functions.

+
+ggdraw(p) + 
+  draw_label("Draft", color = "#C0A0A0", size = 100, angle = 45)

-

What ggdraw(p) does is it captures a snapshot of the plot, so that the plot effectively turns into an image, and then it draws that image into a new ggplot2 canvas without visible axes or background grid. The draw_* functions are simply wrappers around regular geoms. So, in the above example we could have used geom_text() instead of draw_label().

-
-ggdraw(p) + 
-  geom_text(
-    data = data.frame(x = 0.5, y = 0.5, label = "Draft"),
-    aes(x, y, label = label),
-    hjust = 0.5, vjust = 0.5, angle = 45, size = 100/.pt,
-    color = "#C0A0A0",
-    inherit.aes = FALSE
-  )
-
+

What ggdraw(p) does is it captures a snapshot of the +plot, so that the plot effectively turns into an image, and then it +draws that image into a new ggplot2 canvas without visible axes or +background grid. The draw_* functions are simply wrappers +around regular geoms. So, in the above example we could have used +geom_text() instead of draw_label().

+
+ggdraw(p) + 
+  geom_text(
+    data = data.frame(x = 0.5, y = 0.5, label = "Draft"),
+    aes(x, y, label = label),
+    hjust = 0.5, vjust = 0.5, angle = 45, size = 100/.pt,
+    color = "#C0A0A0",
+    inherit.aes = FALSE
+  )

-

However, notice how much more verbose the call to geom_text() is. Also, geom_text() interprets font sizes in mm, so we need to divide by .pt if we want to specify font sizes in the more conventional point metric. By contrast, draw_label() performs this conversion for us, so we can specify font sizes directly in points.

-

Because ggdraw() is built on top of ggplot2, we can treat its output like a ggplot2 plot. For example, we can use the theme() function to change the background color.

-
-ggdraw(p) + 
-  draw_label("Draft", color = "#C0A0A0", size = 100, angle = 45) +
-  theme(
-    plot.background = element_rect(fill = "cornsilk", color = NA)
-  )
-
+

However, notice how much more verbose the call to +geom_text() is. Also, geom_text() interprets +font sizes in mm, so we need to divide by .pt if we want to +specify font sizes in the more conventional point metric. By contrast, +draw_label() performs this conversion for us, so we can +specify font sizes directly in points.

+

Because ggdraw() is built on top of ggplot2, we can +treat its output like a ggplot2 plot. For example, we can use the +theme() function to change the background color.

+
+ggdraw(p) + 
+  draw_label("Draft", color = "#C0A0A0", size = 100, angle = 45) +
+  theme(
+    plot.background = element_rect(fill = "cornsilk", color = NA)
+  )

-

We can also save the annotated plots in the standard way via ggsave().

-
-draft <- ggdraw(p) + 
-  draw_label("Draft", color = "#C0A0A0", size = 100, angle = 45)
-
-ggsave("draft.pdf", draft)
-
-

(However, the cowplot package provides an alternative to ggsave(), the function save_plot(), which makes it easier to save plots with appropriate sizing, in particular when making compound plots. See the documentation of save_plot() for details.)

-

Frequently, we may want to have the annotations underneath the plot rather than on top of it. We can achieve this effect by first setting up an empty drawing layer with ggdraw(), then adding the label, and then adding the plot with draw_plot().

-
-ggdraw() + 
-  draw_label("Draft", color = "#C0A0A0", size = 100, angle = 45) +
-  draw_plot(p)
-
+

We can also save the annotated plots in the standard way via +ggsave().

+
+draft <- ggdraw(p) + 
+  draw_label("Draft", color = "#C0A0A0", size = 100, angle = 45)
+
+ggsave("draft.pdf", draft)
+

(However, the cowplot package provides an alternative to +ggsave(), the function save_plot(), which +makes it easier to save plots with appropriate sizing, in particular +when making compound plots. See the documentation of +save_plot() for details.)

+

Frequently, we may want to have the annotations underneath the plot +rather than on top of it. We can achieve this effect by first setting up +an empty drawing layer with ggdraw(), then adding the +label, and then adding the plot with draw_plot().

+
+ggdraw() + 
+  draw_label("Draft", color = "#C0A0A0", size = 100, angle = 45) +
+  draw_plot(p)

-

This requires that the plot has a transparent background, and all cowplot themes meet this requirement. By contrast, this is not necessarily the case for ggplot2 themes. For example, if we change the theme of the plot to theme_classic() the underlying label is hidden by the theme’s white background.

-
-ggdraw() + 
-  draw_label("Draft", color = "#C0A0A0", size = 100, angle = 45) +
-  draw_plot(
-    p + theme_classic()
-  )
-
+

This requires that the plot has a transparent background, and all +cowplot themes meet this requirement. By contrast, this is not +necessarily the case for ggplot2 themes. For example, if we change the +theme of the plot to theme_classic() the underlying label +is hidden by the theme’s white background.

+
+ggdraw() + 
+  draw_label("Draft", color = "#C0A0A0", size = 100, angle = 45) +
+  draw_plot(
+    p + theme_classic()
+  )

-

The cowplot theme theme_half_open() does not have this limitation.

-
-ggdraw() + 
-  draw_label("Draft", color = "#C0A0A0", size = 100, angle = 45) +
-  draw_plot(
-    p + theme_half_open(12)
-  )
-
+

The cowplot theme theme_half_open() does not have this +limitation.

+
+ggdraw() + 
+  draw_label("Draft", color = "#C0A0A0", size = 100, angle = 45) +
+  draw_plot(
+    p + theme_half_open(12)
+  )

-
-

-Making inset plots

-

The draw_plot() function also allows us to place plots at arbitrary locations and at arbitrary sizes onto the canvas. This is useful for combining subplots into a layout that is not a simple grid, e.g. with an inset plotted inside a larger graph.

-
-inset <- ggplot(mpg, aes(drv)) + 
-  geom_bar(fill = "skyblue2", alpha = 0.7) + 
-  scale_y_continuous(expand = expansion(mult = c(0, 0.05))) +
-  theme_minimal_hgrid(11)
-
-ggdraw(p + theme_half_open(12)) +
-  draw_plot(inset, .45, .45, .5, .5) +
-  draw_plot_label(
-    c("A", "B"),
-    c(0, 0.45),
-    c(1, 0.95),
-    size = 12
-  )
-
+
+

Making inset plots +

+

The draw_plot() function also allows us to place plots +at arbitrary locations and at arbitrary sizes onto the canvas. This is +useful for combining subplots into a layout that is not a simple grid, +e.g. with an inset plotted inside a larger graph.

+
+inset <- ggplot(mpg, aes(drv)) + 
+  geom_bar(fill = "skyblue2", alpha = 0.7) + 
+  scale_y_continuous(expand = expansion(mult = c(0, 0.05))) +
+  theme_minimal_hgrid(11)
+
+ggdraw(p + theme_half_open(12)) +
+  draw_plot(inset, .45, .45, .5, .5) +
+  draw_plot_label(
+    c("A", "B"),
+    c(0, 0.45),
+    c(1, 0.95),
+    size = 12
+  )

-

This feature is not limited to ggplot2 plots. It works with base graphics as well.

-
-inset <- ~{
-  counts <- table(mpg$drv)
-  par(
-    cex = 0.8,
-    mar = c(3, 3, 1, 1),
-    mgp = c(2, 1, 0)
-  )
-  barplot(counts, xlab = "drv", ylab = "count")
-}
-
-ggdraw(p + theme_half_open(12)) +
-  draw_plot(inset, .45, .45, .5, .5) +
-  draw_plot_label(
-    c("A", "B"),
-    c(0, 0.45),
-    c(1, 0.95),
-    size = 12
-  )
-
+

This feature is not limited to ggplot2 plots. It works with base +graphics as well.

+
+inset <- ~{
+  counts <- table(mpg$drv)
+  par(
+    cex = 0.8,
+    mar = c(3, 3, 1, 1),
+    mgp = c(2, 1, 0)
+  )
+  barplot(counts, xlab = "drv", ylab = "count")
+}
+
+ggdraw(p + theme_half_open(12)) +
+  draw_plot(inset, .45, .45, .5, .5) +
+  draw_plot_label(
+    c("A", "B"),
+    c(0, 0.45),
+    c(1, 0.95),
+    size = 12
+  )

-
-

-Absolute positioning

-

By default, the coordinate system used by ggdraw() uses relative coordinates running from 0 to 1 for both x and y. Sometimes, however, we need to be able to place graphical elements at absolute units, e.g. exactly 1 inch from the left border. We can do so via the grid graphic system, which is supported through the draw_grob() function. For example, the following code generates a blue square of 1 inch width and height that is located exactly 1 inch from the left and 1 inch from the top border of the plot area.

-
-library(grid)
-rect <- rectGrob(
-  x = unit(1, "in"),
-  y = unit(1, "npc") - unit(1, "in"),
-  width = unit(1, "in"),
-  height = unit(1, "in"),
-  hjust = 0, vjust = 1,
-  gp = gpar(fill = "skyblue2", alpha = 0.5)
-)
-
-ggdraw(p) +
-  draw_grob(rect)
-
+
+

Absolute positioning +

+

By default, the coordinate system used by ggdraw() uses +relative coordinates running from 0 to 1 for both x and y. Sometimes, +however, we need to be able to place graphical elements at absolute +units, e.g. exactly 1 inch from the left border. We can do so via the +grid graphic system, which is supported through the +draw_grob() function. For example, the following code +generates a blue square of 1 inch width and height that is located +exactly 1 inch from the left and 1 inch from the top border of the plot +area.

+
+library(grid)
+rect <- rectGrob(
+  x = unit(1, "in"),
+  y = unit(1, "npc") - unit(1, "in"),
+  width = unit(1, "in"),
+  height = unit(1, "in"),
+  hjust = 0, vjust = 1,
+  gp = gpar(fill = "skyblue2", alpha = 0.5)
+)
+
+ggdraw(p) +
+  draw_grob(rect)

-

If we regenerate the plot in a different size, the blue square remains at the same absolute position and retains its absolute size.

-
-ggdraw(p) +
-  draw_grob(rect)
-
+

If we regenerate the plot in a different size, the blue square +remains at the same absolute position and retains its absolute size.

+
+ggdraw(p) +
+  draw_grob(rect)

-
-

-Combining plots and images

-

The drawing layer also supports images, through the function draw_image(). This function, which requires the magick package to be installed, can take images in many different formats and combine them with plots. For example, we can use an image as a plot background:

-
-library(magick)
-library(dplyr)
-library(forcats)
-
-img <- system.file("extdata", "cow.jpg", package = "cowplot") %>%
-  image_read() %>%
-  image_resize("570x380") %>%
-  image_colorize(35, "white")
-
-p <- PASWR::Cows %>%
-  filter(breed != "Canadian") %>%
-  mutate(breed = fct_reorder(breed, butterfat)) %>%
-  ggplot(aes(butterfat, fill = breed)) +
-  geom_density(alpha = 0.7) +
-  scale_fill_grey() +
-  coord_cartesian(expand = FALSE) +
-  theme_minimal_hgrid(11, color = "grey30")
-
-ggdraw() + 
-  draw_image(img) + 
-  draw_plot(p)
-
+
+

Combining plots and images +

+

The drawing layer also supports images, through the function +draw_image(). This function, which requires the magick package to +be installed, can take images in many different formats and combine them +with plots. For example, we can use an image as a plot background:

+
+library(magick)
+library(dplyr)
+library(forcats)
+
+img <- system.file("extdata", "cow.jpg", package = "cowplot") %>%
+  image_read() %>%
+  image_resize("570x380") %>%
+  image_colorize(35, "white")
+
+p <- PASWR::Cows %>%
+  filter(breed != "Canadian") %>%
+  mutate(breed = fct_reorder(breed, butterfat)) %>%
+  ggplot(aes(butterfat, fill = breed)) +
+  geom_density(alpha = 0.7) +
+  scale_fill_grey() +
+  coord_cartesian(expand = FALSE) +
+  theme_minimal_hgrid(11, color = "grey30")
+
+ggdraw() + 
+  draw_image(img) + 
+  draw_plot(p)

-

We can also add an image as a logo onto a plot. We use halign and valign in addition to hjust and vjust to align the image flush in the top right corner.

-
-logo_file <- system.file("extdata", "logo.png", package = "cowplot")
-
-ggdraw() + 
-  draw_plot(p) +
-  draw_image(
-    logo_file, x = 1, y = 1, hjust = 1, vjust = 1, halign = 1, valign = 1,
-    width = 0.15
-  )
-
+

We can also add an image as a logo onto a plot. We use +halign and valign in addition to +hjust and vjust to align the image flush in +the top right corner.

+
+logo_file <- system.file("extdata", "logo.png", package = "cowplot")
+
+ggdraw() + 
+  draw_plot(p) +
+  draw_image(
+    logo_file, x = 1, y = 1, hjust = 1, vjust = 1, halign = 1, valign = 1,
+    width = 0.15
+  )

@@ -320,11 +358,13 @@

-

Site built with pkgdown 1.6.0.

+

+

Site built with pkgdown 2.0.7.

@@ -333,5 +373,7 @@

+ + diff --git a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-10-1.png b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-10-1.png index 69e17ff..f574f67 100644 Binary files a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-10-1.png and b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-10-1.png differ diff --git a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-11-1.png b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-11-1.png index b32300e..f218a51 100644 Binary files a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-11-1.png and b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-11-1.png differ diff --git a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-12-1.png b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-12-1.png index 27a4cc2..90deba1 100644 Binary files a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-12-1.png and b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-12-1.png differ diff --git a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-13-1.png b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-13-1.png index 719d3dd..e82c9ad 100644 Binary files a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-13-1.png and b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-13-1.png differ diff --git a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-14-1.png b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-14-1.png index dd780d3..a1e7d39 100644 Binary files a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-14-1.png and b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-14-1.png differ diff --git a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-15-1.png b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-15-1.png index a6c7a49..98d39cf 100644 Binary files a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-15-1.png and b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-15-1.png differ diff --git a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-2-1.png b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-2-1.png index 81d2f7f..9bf906c 100644 Binary files a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-2-1.png and b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-2-1.png differ diff --git a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-3-1.png b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-3-1.png index 4144a23..f19ffb9 100644 Binary files a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-3-1.png and b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-3-1.png differ diff --git a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-4-1.png index 4144a23..f19ffb9 100644 Binary files a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-4-1.png and b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-5-1.png index 86fc302..be20f7b 100644 Binary files a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-5-1.png and b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-7-1.png b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-7-1.png index 6cd7ddd..c6efe10 100644 Binary files a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-7-1.png and b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-7-1.png differ diff --git a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-8-1.png b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-8-1.png index 64f573d..f107129 100644 Binary files a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-8-1.png and b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-8-1.png differ diff --git a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-9-1.png b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-9-1.png index 47c891f..579dbea 100644 Binary files a/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-9-1.png and b/docs/articles/drawing_with_on_plots_files/figure-html/unnamed-chunk-9-1.png differ diff --git a/docs/articles/index.html b/docs/articles/index.html index f7cd94f..5d80211 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -1,74 +1,12 @@ - - - - - - - -Articles • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Articles • cowplot - + + - - - -
-
- -
- - -
- +
- - + + diff --git a/docs/articles/introduction.html b/docs/articles/introduction.html index 9610faa..5ce60e5 100644 --- a/docs/articles/introduction.html +++ b/docs/articles/introduction.html @@ -26,6 +26,8 @@ + +
+
-

The cowplot package is a simple add-on to ggplot. It provides various features that help with creating publication-quality figures, such as a set of themes, functions to align plots and arrange them into complex compound figures, and functions that make it easy to annotate plots and or mix plots with images. The package was originally written for internal use in my lab, to provide my students and postdocs with the tools to make high-quality figures for their publications. I have also used the package extensively in my book Fundamentals of Data Visualization. This introductory vignette provides a brief glance at the key features of the package.

-

For more complete documentation, read all vignettes and/or the reference documentation.

-
-

-Themes

-

When I first wrote the cowplot package, its primary purpose was to provide a simple and clean theme, similar to ggplot2’s theme_classic(). Therefore, I wrote the package to automatically load the theme. However, as the package grew in functionality, this choice was increasingly problematic, and therefore as of version 1.0 cowplot does not alter the default ggplot2 theme anymore.

-

Importantly, the cowplot package now provides a set of complementary themes with different features. I now believe that there isn’t one single theme that works for all figures, and therefore I recommend that you always explicitly set a theme for every plot you make.

-
-library(ggplot2)
-library(cowplot)
-
-# default ggplot2 theme
-ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + 
-  geom_point()
-
+

The cowplot package is a simple add-on to ggplot. It provides various +features that help with creating publication-quality figures, such as a +set of themes, functions to align plots and arrange them into complex +compound figures, and functions that make it easy to annotate plots and +or mix plots with images. The package was originally written for +internal use in my lab, to provide my students and postdocs with the +tools to make high-quality figures for their publications. I have also +used the package extensively in my book Fundamentals of Data +Visualization. This introductory vignette provides a brief glance at +the key features of the package.

+

For more complete documentation, read all +vignettes and/or the reference +documentation.

+
+

Themes +

+

When I first wrote the cowplot package, its primary purpose was to +provide a simple and clean theme, similar to ggplot2’s +theme_classic(). Therefore, I wrote the package to +automatically load the theme. However, as the package grew in +functionality, this choice was increasingly problematic, and therefore +as of version 1.0 cowplot does not alter the default ggplot2 theme +anymore.

+

Importantly, the cowplot package now provides a set of complementary +themes with different features. I now believe that there isn’t one +single theme that works for all figures, and therefore I recommend that +you always explicitly set a theme for every plot you make.

+
+library(ggplot2)
+library(cowplot)
+
+# default ggplot2 theme
+ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + 
+  geom_point()

-
-# classic cowplot theme
-ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + 
-  geom_point() +
-  theme_cowplot(12)
-
+
+# classic cowplot theme
+ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + 
+  geom_point() +
+  theme_cowplot(12)

-
-# minimal grid theme
-ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + 
-  geom_point() +
-  theme_minimal_grid(12)
-
+
+# minimal grid theme
+ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + 
+  geom_point() +
+  theme_minimal_grid(12)

-
-# minimal horizontal grid theme
-ggplot(iris, aes(Sepal.Length, fill = Species)) + 
-  geom_density(alpha = 0.5) +
-  scale_y_continuous(expand = expansion(mult = c(0, 0.05))) +
-  theme_minimal_hgrid(12)
-
+
+# minimal horizontal grid theme
+ggplot(iris, aes(Sepal.Length, fill = Species)) + 
+  geom_density(alpha = 0.5) +
+  scale_y_continuous(expand = expansion(mult = c(0, 0.05))) +
+  theme_minimal_hgrid(12)

-

However, if you have existing code that depends on the old cowplot behavior, you can call theme_set(theme_cowplot()) at the top of your script to change the theme globally.

+

However, if you have existing code that depends on the old cowplot +behavior, you can call theme_set(theme_cowplot()) at the +top of your script to change the theme globally.

-
-

-Arranging plots into a grid

-

The cowplot package provides the function plot_grid() to arrange plots into a grid and label them.

-
-p1 <- ggplot(mtcars, aes(disp, mpg)) + 
-  geom_point()
-p2 <- ggplot(mtcars, aes(qsec, mpg)) +
-  geom_point()
-
-plot_grid(p1, p2, labels = c('A', 'B'), label_size = 12)
-
+
+

Arranging plots into a grid +

+

The cowplot package provides the function plot_grid() to +arrange plots into a grid and label them.

+
+p1 <- ggplot(mtcars, aes(disp, mpg)) + 
+  geom_point()
+p2 <- ggplot(mtcars, aes(qsec, mpg)) +
+  geom_point()
+
+plot_grid(p1, p2, labels = c('A', 'B'), label_size = 12)

-

While plot_grid() was originally written for ggplot2, it also supports other plotting frameworks, such as base graphics.

-
-p3 <- ~plot(mtcars$qsec, mtcars$mpg)
-
-plot_grid(p1, p3, labels = c('A', 'B'), label_size = 12)
-
+

While plot_grid() was originally written for ggplot2, it +also supports other plotting frameworks, such as base graphics.

+
+p3 <- ~plot(mtcars$qsec, mtcars$mpg)
+
+plot_grid(p1, p3, labels = c('A', 'B'), label_size = 12)

-
-

-Generic plot annotations

-

The plot_grid() is built on top of a generic drawing layer that allows us to capture plots as images and then draw with them or on top of them.

-
-p <- ggplot(mtcars, aes(disp, mpg)) + 
-  geom_point(size = 1.5, color = "blue") +
-  theme_cowplot(12)
-
-logo_file <- system.file("extdata", "logo.png", package = "cowplot")
-
-ggdraw(p) + 
-  draw_image(logo_file, x = 1, y = 1, hjust = 1, vjust = 1, width = 0.13, height = 0.2)
-
+
+

Generic plot annotations +

+

The plot_grid() is built on top of a generic drawing +layer that allows us to capture plots as images and then draw with them +or on top of them.

+
+p <- ggplot(mtcars, aes(disp, mpg)) + 
+  geom_point(size = 1.5, color = "blue") +
+  theme_cowplot(12)
+
+logo_file <- system.file("extdata", "logo.png", package = "cowplot")
+
+ggdraw(p) + 
+  draw_image(logo_file, x = 1, y = 1, hjust = 1, vjust = 1, width = 0.13, height = 0.2)

-

Here, ggdraw() takes a snapshot of the plot and places it at full size into a new drawing canvas. The function draw_image() then draws an image on top of the plot.

-

To create a watermark, we can reverse the order by first setting up an empty drawing canvas, then drawing the image, and then drawing the plot on top.

-
-ggdraw() + 
-  draw_image(logo_file, scale = 0.5) +
-  draw_plot(p)
-
+

Here, ggdraw() takes a snapshot of the plot and places +it at full size into a new drawing canvas. The function +draw_image() then draws an image on top of the plot.

+

To create a watermark, we can reverse the order by first setting up +an empty drawing canvas, then drawing the image, and then drawing the +plot on top.

+
+ggdraw() + 
+  draw_image(logo_file, scale = 0.5) +
+  draw_plot(p)

@@ -217,11 +236,13 @@

-

Site built with pkgdown 1.6.0.

+

+

Site built with pkgdown 2.0.7.

@@ -230,5 +251,7 @@

+ + diff --git a/docs/articles/introduction_files/figure-html/unnamed-chunk-2-1.png b/docs/articles/introduction_files/figure-html/unnamed-chunk-2-1.png index 3dfed61..1cc56fe 100644 Binary files a/docs/articles/introduction_files/figure-html/unnamed-chunk-2-1.png and b/docs/articles/introduction_files/figure-html/unnamed-chunk-2-1.png differ diff --git a/docs/articles/introduction_files/figure-html/unnamed-chunk-2-2.png b/docs/articles/introduction_files/figure-html/unnamed-chunk-2-2.png index f9f7c1a..60971a0 100644 Binary files a/docs/articles/introduction_files/figure-html/unnamed-chunk-2-2.png and b/docs/articles/introduction_files/figure-html/unnamed-chunk-2-2.png differ diff --git a/docs/articles/introduction_files/figure-html/unnamed-chunk-2-3.png b/docs/articles/introduction_files/figure-html/unnamed-chunk-2-3.png index ab630dc..2eeb351 100644 Binary files a/docs/articles/introduction_files/figure-html/unnamed-chunk-2-3.png and b/docs/articles/introduction_files/figure-html/unnamed-chunk-2-3.png differ diff --git a/docs/articles/introduction_files/figure-html/unnamed-chunk-2-4.png b/docs/articles/introduction_files/figure-html/unnamed-chunk-2-4.png index 81de5b5..64463d6 100644 Binary files a/docs/articles/introduction_files/figure-html/unnamed-chunk-2-4.png and b/docs/articles/introduction_files/figure-html/unnamed-chunk-2-4.png differ diff --git a/docs/articles/introduction_files/figure-html/unnamed-chunk-3-1.png b/docs/articles/introduction_files/figure-html/unnamed-chunk-3-1.png index 54777ce..190f6cf 100644 Binary files a/docs/articles/introduction_files/figure-html/unnamed-chunk-3-1.png and b/docs/articles/introduction_files/figure-html/unnamed-chunk-3-1.png differ diff --git a/docs/articles/introduction_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/introduction_files/figure-html/unnamed-chunk-4-1.png index 2663eb5..d9342f1 100644 Binary files a/docs/articles/introduction_files/figure-html/unnamed-chunk-4-1.png and b/docs/articles/introduction_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/introduction_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/introduction_files/figure-html/unnamed-chunk-5-1.png index 3ccb316..cc6fcf5 100644 Binary files a/docs/articles/introduction_files/figure-html/unnamed-chunk-5-1.png and b/docs/articles/introduction_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/introduction_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/introduction_files/figure-html/unnamed-chunk-6-1.png index cb37e62..1dadc42 100644 Binary files a/docs/articles/introduction_files/figure-html/unnamed-chunk-6-1.png and b/docs/articles/introduction_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/mixing_plot_frameworks.html b/docs/articles/mixing_plot_frameworks.html index 2ddec41..ea7fca6 100644 --- a/docs/articles/mixing_plot_frameworks.html +++ b/docs/articles/mixing_plot_frameworks.html @@ -26,6 +26,8 @@ + +
+
-

All cowplot functions that take plot objects as input (ggdraw(), draw_plot(), plot_grid()) can handle several different types of objects in addition to ggplot2 objects. Most importantly, they can handle plots produced with base R graphics. However, this functionality is only available if you have the package gridGraphics installed.

-

As the first example, we draw a base graphics plot with ggdraw() and style the background with the ggplot2 themeing mechanism.

-
-library(ggplot2)
-library(cowplot)
-
-# define a function that emits the desired plot
-p1 <- function() {
-  par(
-    mar = c(3, 3, 1, 1),
-    mgp = c(2, 1, 0)
-  )
-  boxplot(mpg ~ cyl, xlab = "cyl", ylab = "mpg", data = mtcars)
-}
-
-ggdraw(p1) +
-  theme(plot.background = element_rect(fill = "cornsilk"))
-
+

All cowplot functions that take plot objects as input +(ggdraw(), draw_plot(), +plot_grid()) can handle several different types of objects +in addition to ggplot2 objects. Most importantly, they can handle plots +produced with base R graphics. However, this functionality is only +available if you have the package gridGraphics +installed.

+

As the first example, we draw a base graphics plot with +ggdraw() and style the background with the ggplot2 themeing +mechanism.

+
+library(ggplot2)
+library(cowplot)
+
+# define a function that emits the desired plot
+p1 <- function() {
+  par(
+    mar = c(3, 3, 1, 1),
+    mgp = c(2, 1, 0)
+  )
+  boxplot(mpg ~ cyl, xlab = "cyl", ylab = "mpg", data = mtcars)
+}
+
+ggdraw(p1) +
+  theme(plot.background = element_rect(fill = "cornsilk"))

We can also add a logo to the plot.

-
-logo_file <- system.file("extdata", "logo.png", package = "cowplot")
-
-ggdraw() + 
-  draw_image(
-    logo_file,
-    x = 1, width = 0.1,
-    hjust = 1, halign = 1, valign = 0
-  ) +
-  draw_plot(p1)
-
+
+logo_file <- system.file("extdata", "logo.png", package = "cowplot")
+
+ggdraw() + 
+  draw_image(
+    logo_file,
+    x = 1, width = 0.1,
+    hjust = 1, halign = 1, valign = 0
+  ) +
+  draw_plot(p1)

-

And we can draw base graphics and ggplot2 graphics side-by-side in a plot grid.

-
-p2 <- ggplot(data = mtcars, aes(factor(cyl), mpg)) + geom_boxplot()
-plot_grid(p1, p2)
-
+

And we can draw base graphics and ggplot2 graphics side-by-side in a +plot grid.

+
+p2 <- ggplot(data = mtcars, aes(factor(cyl), mpg)) + geom_boxplot()
+plot_grid(p1, p2)

-

Base R plots can be stored in the form of functions that emit the desired plots (demonstrated above), as recorded plots, or using a convenient formula interface.

-

To create a recorded plot, we first draw the base plot, then we record it with recordPlot(), and then we can draw it with ggdraw().

-
-# create base R plot
-par(mar = c(3, 3, 1, 1), mgp = c(2, 1, 0))
-boxplot(mpg ~ cyl, xlab = "cyl", ylab = "mpg", data = mtcars)
-
+

Base R plots can be stored in the form of functions that emit the +desired plots (demonstrated above), as recorded plots, or using a +convenient formula interface.

+

To create a recorded plot, we first draw the base plot, then we +record it with recordPlot(), and then we can draw it with +ggdraw().

+
+# create base R plot
+par(mar = c(3, 3, 1, 1), mgp = c(2, 1, 0))
+boxplot(mpg ~ cyl, xlab = "cyl", ylab = "mpg", data = mtcars)

-
-# record previous base R plot and then draw through ggdraw()
-p1_recorded <- recordPlot()
-ggdraw(p1_recorded)
-
+
+# record previous base R plot and then draw through ggdraw()
+p1_recorded <- recordPlot()
+ggdraw(p1_recorded)

-

We can store arbitrarily complex plotting code in formulas by enclosing it into curly braces.

-
-# store base R plot as formula
-p1_formula <- ~{
-  par(
-    mar = c(3, 3, 1, 1), 
-    mgp = c(2, 1, 0)
-  )
-  boxplot(mpg ~ cyl, xlab = "cyl", ylab = "mpg", data = mtcars)
-}
-ggdraw(p1_formula)
-
+

We can store arbitrarily complex plotting code in formulas by +enclosing it into curly braces.

+
+# store base R plot as formula
+p1_formula <- ~{
+  par(
+    mar = c(3, 3, 1, 1), 
+    mgp = c(2, 1, 0)
+  )
+  boxplot(mpg ~ cyl, xlab = "cyl", ylab = "mpg", data = mtcars)
+}
+ggdraw(p1_formula)

There is also support for lattice graphics and grid grobs.

-
-# base R
-p1 <- ~{
-  par(
-    mar = c(3, 3, 1, 1), 
-    mgp = c(2, 1, 0)
-  )
-  boxplot(mpg ~ cyl, xlab = "cyl", ylab = "mpg", data = mtcars)
-}
-
-# ggplot2
-p2 <- ggplot(data = mtcars, aes(factor(cyl), mpg)) + geom_boxplot()
-
-# lattice
-library(lattice)
-p3 <- bwplot(~mpg | cyl, data = mtcars)
-
-# elementary grid graphics objects
-library(grid)
-p4 <- circleGrob(r = 0.3, gp = gpar(fill = "skyblue"))
-
-# combine all into one plot
-plot_grid(p1, p2, p3, p4, rel_heights = c(.6, 1), labels = "auto")
-
+
+# base R
+p1 <- ~{
+  par(
+    mar = c(3, 3, 1, 1), 
+    mgp = c(2, 1, 0)
+  )
+  boxplot(mpg ~ cyl, xlab = "cyl", ylab = "mpg", data = mtcars)
+}
+
+# ggplot2
+p2 <- ggplot(data = mtcars, aes(factor(cyl), mpg)) + geom_boxplot()
+
+# lattice
+library(lattice)
+p3 <- bwplot(~mpg | cyl, data = mtcars)
+
+# elementary grid graphics objects
+library(grid)
+p4 <- circleGrob(r = 0.3, gp = gpar(fill = "skyblue"))
+
+# combine all into one plot
+plot_grid(p1, p2, p3, p4, rel_heights = c(.6, 1), labels = "auto")

Other packages are supported as long as they return grid grobs.

-
-library(VennDiagram)
-
-p_venn <- draw.pairwise.venn(
-  100, 70, 30,
-  c("First", "Second"),
-  fill = c("light blue", "pink"),
-  alpha = c(0.7, 0.7),
-  ind = FALSE
-)
-
-# plot venn diagram and add some margin and enclosing box
-ggdraw(p_venn) +
-  theme(
-    plot.background = element_rect(fill = NA),
-    plot.margin = margin(12, 12, 12, 12)
-  )
-
+
+library(VennDiagram)
+
+p_venn <- draw.pairwise.venn(
+  100, 70, 30,
+  c("First", "Second"),
+  fill = c("light blue", "pink"),
+  alpha = c(0.7, 0.7),
+  ind = FALSE
+)
+
+# plot venn diagram and add some margin and enclosing box
+ggdraw(p_venn) +
+  theme(
+    plot.background = element_rect(fill = NA),
+    plot.margin = margin(12, 12, 12, 12)
+  )

@@ -241,11 +244,13 @@

2020-12-15

-

Site built with pkgdown 1.6.0.

+

+

Site built with pkgdown 2.0.7.

@@ -254,5 +259,7 @@

2020-12-15

+ + diff --git a/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-2-1.png b/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-2-1.png index c76225a..d38fe0c 100644 Binary files a/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-2-1.png and b/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-2-1.png differ diff --git a/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-3-1.png b/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-3-1.png index d048999..88de12e 100644 Binary files a/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-3-1.png and b/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-3-1.png differ diff --git a/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-4-1.png index 882f3e2..7ce21f9 100644 Binary files a/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-4-1.png and b/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-5-1.png index 11896af..b61c3dd 100644 Binary files a/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-5-1.png and b/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-5-2.png b/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-5-2.png index 11896af..b61c3dd 100644 Binary files a/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-5-2.png and b/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-5-2.png differ diff --git a/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-6-1.png index 11896af..b61c3dd 100644 Binary files a/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-6-1.png and b/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-7-1.png b/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-7-1.png index 2247e0d..009cc3a 100644 Binary files a/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-7-1.png and b/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-7-1.png differ diff --git a/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-8-1.png b/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-8-1.png index c43c305..884e719 100644 Binary files a/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-8-1.png and b/docs/articles/mixing_plot_frameworks_files/figure-html/unnamed-chunk-8-1.png differ diff --git a/docs/articles/plot_grid.html b/docs/articles/plot_grid.html index 68b0077..7fc7001 100644 --- a/docs/articles/plot_grid.html +++ b/docs/articles/plot_grid.html @@ -26,6 +26,8 @@ + +
+
-

This vignette covers the function plot_grid(), which can be used to create table-like layouts of plots. This functionality is built on top of the cowplot drawing layer implemented in ggdraw() and draw_*(), and it aligns plots via the align_plots() function. It is strongly recommended to read the vignettes on these two sets of features (the vignettes called “Drawing with and on plots” and “Aligning plots”) to fully understand how plot_grid() works.

-
-

-Basic usage

-

The plot_grid() function provides a simple interface for arranging plots into a grid and adding labels to them.

-
-library(ggplot2)
-library(cowplot)
-
-p1 <- ggplot(mtcars, aes(disp, mpg)) + 
-  geom_point()
-p2 <- ggplot(mtcars, aes(qsec, mpg)) +
-  geom_point()
-
-plot_grid(p1, p2, labels = c('A', 'B'))
-
+

This vignette covers the function plot_grid(), which can +be used to create table-like layouts of plots. This functionality is +built on top of the cowplot drawing layer implemented in +ggdraw() and draw_*(), and it aligns plots via +the align_plots() function. It is strongly recommended to +read the vignettes on these two sets of features (the vignettes called +“Drawing with and on plots” and “Aligning plots”) to fully understand +how plot_grid() works.

+
+

Basic usage +

+

The plot_grid() function provides a simple interface for +arranging plots into a grid and adding labels to them.

+
+library(ggplot2)
+library(cowplot)
+
+p1 <- ggplot(mtcars, aes(disp, mpg)) + 
+  geom_point()
+p2 <- ggplot(mtcars, aes(qsec, mpg)) +
+  geom_point()
+
+plot_grid(p1, p2, labels = c('A', 'B'))

-

If you specify the labels as labels = "AUTO" or labels = "auto" then labels will be auto-generated in upper or lower case, respectively.

-
-plot_grid(p1, p2, labels = "AUTO")
-
+

If you specify the labels as labels = "AUTO" or +labels = "auto" then labels will be auto-generated in upper +or lower case, respectively.

+
+plot_grid(p1, p2, labels = "AUTO")

-
-plot_grid(p1, p2, labels = "auto")
-
+
+plot_grid(p1, p2, labels = "auto")

-

By default, the plots are not aligned, but in many cases they can be aligned via the align option.

-
-p3 <- p1 + 
-  # use large, rotated axis tick labels to highlight alignment issues
-  theme(axis.text.x = element_text(size = 14, angle = 90, vjust = 0.5))
-
-# plots are drawn without alignment
-plot_grid(p3, p2, labels = "AUTO")
-
+

By default, the plots are not aligned, but in many cases they can be +aligned via the align option.

+
+p3 <- p1 + 
+  # use large, rotated axis tick labels to highlight alignment issues
+  theme(axis.text.x = element_text(size = 14, angle = 90, vjust = 0.5))
+
+# plots are drawn without alignment
+plot_grid(p3, p2, labels = "AUTO")

-
-# plots are drawn with horizontal alignment
-plot_grid(p3, p2, labels = "AUTO", align = "h")
-
+
+# plots are drawn with horizontal alignment
+plot_grid(p3, p2, labels = "AUTO", align = "h")

-

For more complex plot arrangements or other specific effects, you may have to specify the axis argument in addition to the align argument. See the vignette on aligning plots for details.

-

The function plot_grid() can handle a variety of different types of plots and graphic objects, not just ggplot2 plots. See the vignette on mixing different plotting frameworks for details. However, alignment of plots is only supported for ggplot2 plots.

+

For more complex plot arrangements or other specific effects, you may +have to specify the axis argument in addition to the +align argument. See the vignette on aligning plots for +details.

+

The function plot_grid() can handle a variety of +different types of plots and graphic objects, not just ggplot2 plots. +See the vignette on mixing different plotting frameworks for details. +However, alignment of plots is only supported for ggplot2 plots.

-
-

-Fine-tuning the plot grid

-

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.

-
-plot_grid(p1, p2, labels = "AUTO", label_size = 12)
-
+
+

Fine-tuning the plot grid +

+

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.

+
+plot_grid(p1, p2, labels = "AUTO", label_size = 12)

-

You can also adjust the font family, font face, and color of the labels.

-
-plot_grid(
-  p1, p2,
-  labels = "AUTO", 
-  label_fontfamily = "serif",
-  label_fontface = "plain",
-  label_colour = "blue"
-)
-
+

You can also adjust the font family, font face, and color of the +labels.

+
+plot_grid(
+  p1, p2,
+  labels = "AUTO", 
+  label_fontfamily = "serif",
+  label_fontface = "plain",
+  label_colour = "blue"
+)

-

Labels can be moved via the label_x and label_y arguments, and justified via the hjust and vjust arguments. For example, to place labels into the bottom left corner, you can write:

-
-plot_grid(
-  p1, p2,
-  labels = "AUTO",
-  label_size = 12,
-  label_x = 0, label_y = 0,
-  hjust = -0.5, vjust = -0.5
-)
-
+

Labels can be moved via the label_x and +label_y arguments, and justified via the hjust +and vjust arguments. For example, to place labels into the +bottom left corner, you can write:

+
+plot_grid(
+  p1, p2,
+  labels = "AUTO",
+  label_size = 12,
+  label_x = 0, label_y = 0,
+  hjust = -0.5, vjust = -0.5
+)

-

It is possible to adjust individual labels one by one by passing vectors of adjustment values to the options label_x, label_y, hjust, and vjust (example not shown).

-

The numbers of rows and columns in the plot grid can be specified via nrow and ncol.

-
-# arrange two plots into one column
-plot_grid(
-  p1, p2,
-  labels = "AUTO", ncol = 1
-)
-
+

It is possible to adjust individual labels one by one by passing +vectors of adjustment values to the options label_x, +label_y, hjust, and vjust +(example not shown).

+

The numbers of rows and columns in the plot grid can be specified via +nrow and ncol.

+
+# arrange two plots into one column
+plot_grid(
+  p1, p2,
+  labels = "AUTO", ncol = 1
+)

-

The argument NULL can be used to indicate a missing plot in the grid. Note that missing plots will be labeled if automatic labeling is turned on.

-
-# the second plot in the first row and the
-# first plot in the second row are missing
-plot_grid(
-  p1, NULL, NULL, p2,
-  labels = "AUTO", ncol = 2
-)
-
+

The argument NULL can be used to indicate a missing plot +in the grid. Note that missing plots will be labeled if automatic +labeling is turned on.

+
+# the second plot in the first row and the
+# first plot in the second row are missing
+plot_grid(
+  p1, NULL, NULL, p2,
+  labels = "AUTO", ncol = 2
+)

-

The relative widths and heights of rows and columns can be adjusted with the rel_widths and rel_heights arguments.

-
-plot_grid(p1, p2, labels = "AUTO", rel_widths = c(1, 2))
-
+

The relative widths and heights of rows and columns can be adjusted +with the rel_widths and rel_heights +arguments.

+
+plot_grid(p1, p2, labels = "AUTO", rel_widths = c(1, 2))

-
-

-Nested plot grids

-

If you want to generate a plot arrangement that is not a simple grid, you may insert one plot_grid() plot into another.

-
-bottom_row <- plot_grid(p1, p2, labels = c('B', 'C'), label_size = 12)
-p3 <- ggplot(mtcars, aes(x = qsec, y = disp)) + geom_point() + facet_wrap(~gear)
-
-plot_grid(p3, bottom_row, labels = c('A', ''), label_size = 12, ncol = 1)
-
+
+

Nested plot grids +

+

If you want to generate a plot arrangement that is not a simple grid, +you may insert one plot_grid() plot into another.

+
+bottom_row <- plot_grid(p1, p2, labels = c('B', 'C'), label_size = 12)
+p3 <- ggplot(mtcars, aes(x = qsec, y = disp)) + geom_point() + facet_wrap(~gear)
+
+plot_grid(p3, bottom_row, labels = c('A', ''), label_size = 12, ncol = 1)

-

Alignment can be a bit tricky in this case. However, it can usually be achieved through an explicit call to align_plots(). The trick is to first align the top-row plot (p3) and the first bottom-row plot (p1) vertically along the left axis, using the align_plots() function. These aligned plots can then be passed to plot_grid().

-
-# first align the top-row plot (p3) with the left-most plot of the
-# bottom row (p1)
-plots <- align_plots(p3, p1, align = 'v', axis = 'l')
-# then build the bottom row
-bottom_row <- plot_grid(plots[[2]], p2, labels = c('B', 'C'), label_size = 12)
-
-# then combine with the top row for final plot
-plot_grid(plots[[1]], bottom_row, labels = c('A', ''), label_size = 12, ncol = 1)
-
+

Alignment can be a bit tricky in this case. However, it can usually +be achieved through an explicit call to align_plots(). The +trick is to first align the top-row plot (p3) and the first +bottom-row plot (p1) vertically along the left axis, using +the align_plots() function. These aligned plots can then be +passed to plot_grid().

+
+# first align the top-row plot (p3) with the left-most plot of the
+# bottom row (p1)
+plots <- align_plots(p3, p1, align = 'v', axis = 'l')
+# then build the bottom row
+bottom_row <- plot_grid(plots[[2]], p2, labels = c('B', 'C'), label_size = 12)
+
+# then combine with the top row for final plot
+plot_grid(plots[[1]], bottom_row, labels = c('A', ''), label_size = 12, ncol = 1)

-
-

-Joint plot titles

-

When we combine plots with plot_grid(), we may want to add a title that spans the entire combined figure. While there is no specific function in cowplot to achieve this effect, it can be simulated easily with a few lines of code:

-
-# make a plot grid consisting of two panels
-p1 <- ggplot(mtcars, aes(x = disp, y = mpg)) + 
-  geom_point(colour = "blue") + 
-  theme_half_open(12) + 
-  background_grid(minor = 'none')
-
-p2 <- ggplot(mtcars, aes(x = hp, y = mpg)) + 
-  geom_point(colour = "green") + 
-  theme_half_open(12) + 
-  background_grid(minor = 'none')
-
-plot_row <- plot_grid(p1, p2)
-
-# now add the title
-title <- ggdraw() + 
-  draw_label(
-    "Miles per gallon decline with displacement and horsepower",
-    fontface = 'bold',
-    x = 0,
-    hjust = 0
-  ) +
-  theme(
-    # add margin on the left of the drawing canvas,
-    # so title is aligned with left edge of first plot
-    plot.margin = margin(0, 0, 0, 7)
-  )
-plot_grid(
-  title, plot_row,
-  ncol = 1,
-  # rel_heights values control vertical title margins
-  rel_heights = c(0.1, 1)
-)
-
+
+

Joint plot titles +

+

When we combine plots with plot_grid(), we may want to +add a title that spans the entire combined figure. While there is no +specific function in cowplot to achieve this effect, it can be simulated +easily with a few lines of code:

+
+# make a plot grid consisting of two panels
+p1 <- ggplot(mtcars, aes(x = disp, y = mpg)) + 
+  geom_point(colour = "blue") + 
+  theme_half_open(12) + 
+  background_grid(minor = 'none')
+
+p2 <- ggplot(mtcars, aes(x = hp, y = mpg)) + 
+  geom_point(colour = "green") + 
+  theme_half_open(12) + 
+  background_grid(minor = 'none')
+
+plot_row <- plot_grid(p1, p2)
+
+# now add the title
+title <- ggdraw() + 
+  draw_label(
+    "Miles per gallon decline with displacement and horsepower",
+    fontface = 'bold',
+    x = 0,
+    hjust = 0
+  ) +
+  theme(
+    # add margin on the left of the drawing canvas,
+    # so title is aligned with left edge of first plot
+    plot.margin = margin(0, 0, 0, 7)
+  )
+plot_grid(
+  title, plot_row,
+  ncol = 1,
+  # rel_heights values control vertical title margins
+  rel_heights = c(0.1, 1)
+)

-

In the final plot_grid line, the values of rel_heights need to be chosen appropriately so that the margins around the title look correct. With the values chosen here, the title takes up 9% (i.e., 0.1/1.1) of the total plot height.

+

In the final plot_grid line, the values of +rel_heights need to be chosen appropriately so that the +margins around the title look correct. With the values chosen here, the +title takes up 9% (i.e., 0.1/1.1) of the total plot height.

@@ -297,11 +323,13 @@

-

Site built with pkgdown 1.6.0.

+

+

Site built with pkgdown 2.0.7.

@@ -310,5 +338,7 @@

+ + diff --git a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-10-1.png b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-10-1.png index 6945d94..51a0d30 100644 Binary files a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-10-1.png and b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-10-1.png differ diff --git a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-11-1.png b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-11-1.png index 25fef54..9dc49e0 100644 Binary files a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-11-1.png and b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-11-1.png differ diff --git a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-12-1.png b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-12-1.png index d7bb56e..54fcb6f 100644 Binary files a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-12-1.png and b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-12-1.png differ diff --git a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-13-1.png b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-13-1.png index 32af5ed..f5857f5 100644 Binary files a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-13-1.png and b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-13-1.png differ diff --git a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-14-1.png b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-14-1.png index fcba0b1..981f959 100644 Binary files a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-14-1.png and b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-14-1.png differ diff --git a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-2-1.png b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-2-1.png index ba9999b..154401f 100644 Binary files a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-2-1.png and b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-2-1.png differ diff --git a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-3-1.png b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-3-1.png index ba9999b..154401f 100644 Binary files a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-3-1.png and b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-3-1.png differ diff --git a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-4-1.png index eb1be17..b092484 100644 Binary files a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-4-1.png and b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-5-1.png index 8dc2e6f..fff035a 100644 Binary files a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-5-1.png and b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-5-2.png b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-5-2.png index 6ce938d..75a8685 100644 Binary files a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-5-2.png and b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-5-2.png differ diff --git a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-6-1.png index 54777ce..190f6cf 100644 Binary files a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-6-1.png and b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-7-1.png b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-7-1.png index 8f2523a..57ec381 100644 Binary files a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-7-1.png and b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-7-1.png differ diff --git a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-8-1.png b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-8-1.png index 3000b4a..2fe7549 100644 Binary files a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-8-1.png and b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-8-1.png differ diff --git a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-9-1.png b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-9-1.png index e7df2de..01a12a9 100644 Binary files a/docs/articles/plot_grid_files/figure-html/unnamed-chunk-9-1.png and b/docs/articles/plot_grid_files/figure-html/unnamed-chunk-9-1.png differ diff --git a/docs/articles/shared_legends.html b/docs/articles/shared_legends.html index 9afe58a..2276e42 100644 --- a/docs/articles/shared_legends.html +++ b/docs/articles/shared_legends.html @@ -26,6 +26,8 @@ + +
+
-

This vignette demonstrates how to make compound plots with a shared legend.

+

This vignette demonstrates how to make compound plots with a shared +legend.

We begin with a row of three plots, without legend.

-
-library(ggplot2)
-library(cowplot)
-library(rlang)
-
-# down-sampled diamonds data set
-dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
-
-# function to create plots
-plot_diamonds <- function(xaes) {
-  xaes <- enquo(xaes)
-  ggplot(dsamp, aes(!!xaes, price, color = clarity)) +
-    geom_point() +
-    theme_half_open(12) +
-    # we set the left and right margins to 0 to remove 
-    # unnecessary spacing in the final plot arrangement.
-    theme(plot.margin = margin(6, 0, 6, 0))
-}
-
-# make three plots
-p1 <- plot_diamonds(carat)
-p2 <- plot_diamonds(depth) + ylab(NULL)
-p3 <- plot_diamonds(color) + ylab(NULL)
-
-# arrange the three plots in a single row
-prow <- plot_grid(
-  p1 + theme(legend.position="none"),
-  p2 + theme(legend.position="none"),
-  p3 + theme(legend.position="none"),
-  align = 'vh',
-  labels = c("A", "B", "C"),
-  hjust = -1,
-  nrow = 1
-)
-prow
-
+
+library(ggplot2)
+library(cowplot)
+library(rlang)
+
+# down-sampled diamonds data set
+dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
+
+# function to create plots
+plot_diamonds <- function(xaes) {
+  xaes <- enquo(xaes)
+  ggplot(dsamp, aes(!!xaes, price, color = clarity)) +
+    geom_point() +
+    theme_half_open(12) +
+    # we set the left and right margins to 0 to remove 
+    # unnecessary spacing in the final plot arrangement.
+    theme(plot.margin = margin(6, 0, 6, 0))
+}
+
+# make three plots
+p1 <- plot_diamonds(carat)
+p2 <- plot_diamonds(depth) + ylab(NULL)
+p3 <- plot_diamonds(color) + ylab(NULL)
+
+# arrange the three plots in a single row
+prow <- plot_grid(
+  p1 + theme(legend.position="none"),
+  p2 + theme(legend.position="none"),
+  p3 + theme(legend.position="none"),
+  align = 'vh',
+  labels = c("A", "B", "C"),
+  hjust = -1,
+  nrow = 1
+)
+prow

-

Now we add the legend back in manually. We can place the legend to the side of the plots.

-
-# extract the legend from one of the plots
-legend <- get_legend(
-  # create some space to the left of the legend
-  p1 + theme(legend.box.margin = margin(0, 0, 0, 12))
-)
-
-# add the legend to the row we made earlier. Give it one-third of 
-# the width of one plot (via rel_widths).
-plot_grid(prow, legend, rel_widths = c(3, .4))
-
+

Now we add the legend back in manually. We can place the legend to +the side of the plots.

+
+# extract the legend from one of the plots
+legend <- get_legend(
+  # create some space to the left of the legend
+  p1 + theme(legend.box.margin = margin(0, 0, 0, 12))
+)
+
+# add the legend to the row we made earlier. Give it one-third of 
+# the width of one plot (via rel_widths).
+plot_grid(prow, legend, rel_widths = c(3, .4))

Or we can place the legend at the bottom.

-
-# extract a legend that is laid out horizontally
-legend_b <- get_legend(
-  p1 + 
-    guides(color = guide_legend(nrow = 1)) +
-    theme(legend.position = "bottom")
-)
-
-# add the legend underneath the row we made earlier. Give it 10%
-# of the height of one plot (via rel_heights).
-plot_grid(prow, legend_b, ncol = 1, rel_heights = c(1, .1))
-
+
+# extract a legend that is laid out horizontally
+legend_b <- get_legend(
+  p1 + 
+    guides(color = guide_legend(nrow = 1)) +
+    theme(legend.position = "bottom")
+)
+
+# add the legend underneath the row we made earlier. Give it 10%
+# of the height of one plot (via rel_heights).
+plot_grid(prow, legend_b, ncol = 1, rel_heights = c(1, .1))

Or we can place the legend between plots.

-
-# arrange the three plots in a single row, leaving space between plot B and C
-prow <- plot_grid(
-  p1 + theme(legend.position="none"),
-  p2 + theme(legend.position="none"),
-  NULL,
-  p3 + theme(legend.position="none"),
-  align = 'vh',
-  labels = c("A", "B", "", "C"),
-  hjust = -1,
-  nrow = 1,
-  rel_widths = c(1, 1, .3, 1)
-)
-
-# now add in the legend
-prow + draw_grob(legend, 2/3.3, 0, .3/3.3, 1)
-
+
+# arrange the three plots in a single row, leaving space between plot B and C
+prow <- plot_grid(
+  p1 + theme(legend.position="none"),
+  p2 + theme(legend.position="none"),
+  NULL,
+  p3 + theme(legend.position="none"),
+  align = 'vh',
+  labels = c("A", "B", "", "C"),
+  hjust = -1,
+  nrow = 1,
+  rel_widths = c(1, 1, .3, 1)
+)
+
+# now add in the legend
+prow + draw_grob(legend, 2/3.3, 0, .3/3.3, 1)

One more example, now with a more complex plot arrangement.

-
-# plot 1
-p1 <- ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + 
-  geom_point() + 
-  stat_smooth(method = "lm") +
-  facet_grid(. ~ Species) +
-  theme_half_open(12) +
-  background_grid(major = 'y', minor = "none") + 
-  panel_border() + 
-  theme(legend.position = "none")
-
-# plot 2
-p2 <- ggplot(iris, aes(Sepal.Length, fill = Species)) +
-  geom_density(alpha = .7) + 
-  scale_y_continuous(expand = expansion(mult = c(0, 0.05))) +
-  theme_half_open(12) +
-  theme(legend.justification = "top")
-p2a <- p2 + theme(legend.position = "none")
-
-# plot 3
-p3 <- ggplot(iris, aes(Sepal.Width, fill = Species)) +
-  geom_density(alpha = .7) + 
-  scale_y_continuous(expand = c(0, 0)) +
-  theme_half_open(12) +
-  theme(legend.position = "none")
-
-# legend
-legend <- get_legend(p2)
-
-# align all plots vertically
-plots <- align_plots(p1, p2a, p3, align = 'v', axis = 'l')
-
-
## `geom_smooth()` using formula 'y ~ x'
-
-# put together the bottom row and then everything
-bottom_row <- plot_grid(
-  plots[[2]], plots[[3]], legend,
-  labels = c("B", "C"),
-  rel_widths = c(1, 1, .3),
-  nrow = 1
-)
-plot_grid(plots[[1]], bottom_row, labels = c("A"), ncol = 1)
-
+
+# plot 1
+p1 <- ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + 
+  geom_point() + 
+  stat_smooth(method = "lm") +
+  facet_grid(. ~ Species) +
+  theme_half_open(12) +
+  background_grid(major = 'y', minor = "none") + 
+  panel_border() + 
+  theme(legend.position = "none")
+
+# plot 2
+p2 <- ggplot(iris, aes(Sepal.Length, fill = Species)) +
+  geom_density(alpha = .7) + 
+  scale_y_continuous(expand = expansion(mult = c(0, 0.05))) +
+  theme_half_open(12) +
+  theme(legend.justification = "top")
+p2a <- p2 + theme(legend.position = "none")
+
+# plot 3
+p3 <- ggplot(iris, aes(Sepal.Width, fill = Species)) +
+  geom_density(alpha = .7) + 
+  scale_y_continuous(expand = c(0, 0)) +
+  theme_half_open(12) +
+  theme(legend.position = "none")
+
+# legend
+legend <- get_legend(p2)
+
+# align all plots vertically
+plots <- align_plots(p1, p2a, p3, align = 'v', axis = 'l')
+
## `geom_smooth()` using formula = 'y ~ x'
+
+# put together the bottom row and then everything
+bottom_row <- plot_grid(
+  plots[[2]], plots[[3]], legend,
+  labels = c("B", "C"),
+  rel_widths = c(1, 1, .3),
+  nrow = 1
+)
+plot_grid(plots[[1]], bottom_row, labels = c("A"), ncol = 1)

@@ -260,11 +253,13 @@

2020-12-15

-

Site built with pkgdown 1.6.0.

+

+

Site built with pkgdown 2.0.7.

@@ -273,5 +268,7 @@

2020-12-15

+ + diff --git a/docs/articles/shared_legends_files/figure-html/unnamed-chunk-2-1.png b/docs/articles/shared_legends_files/figure-html/unnamed-chunk-2-1.png index d6c900e..ef48f17 100644 Binary files a/docs/articles/shared_legends_files/figure-html/unnamed-chunk-2-1.png and b/docs/articles/shared_legends_files/figure-html/unnamed-chunk-2-1.png differ diff --git a/docs/articles/shared_legends_files/figure-html/unnamed-chunk-3-1.png b/docs/articles/shared_legends_files/figure-html/unnamed-chunk-3-1.png index 239fbc2..369505b 100644 Binary files a/docs/articles/shared_legends_files/figure-html/unnamed-chunk-3-1.png and b/docs/articles/shared_legends_files/figure-html/unnamed-chunk-3-1.png differ diff --git a/docs/articles/shared_legends_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/shared_legends_files/figure-html/unnamed-chunk-4-1.png index 9c012e5..da4012c 100644 Binary files a/docs/articles/shared_legends_files/figure-html/unnamed-chunk-4-1.png and b/docs/articles/shared_legends_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/shared_legends_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/shared_legends_files/figure-html/unnamed-chunk-5-1.png index a7133c3..7fb6c0e 100644 Binary files a/docs/articles/shared_legends_files/figure-html/unnamed-chunk-5-1.png and b/docs/articles/shared_legends_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/shared_legends_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/shared_legends_files/figure-html/unnamed-chunk-6-1.png index fb59fed..d750171 100644 Binary files a/docs/articles/shared_legends_files/figure-html/unnamed-chunk-6-1.png and b/docs/articles/shared_legends_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/themes.html b/docs/articles/themes.html index 31c6a2c..9a65f78 100644 --- a/docs/articles/themes.html +++ b/docs/articles/themes.html @@ -26,6 +26,8 @@ + +
+
-

The cowplot package provides a consistent set of plot themes that cover a wide range of use cases. To see these themes in action, check out the book Fundamentals of Data Visualization, which uses them throughout. However, note that the figures in the book use the font Myriad Pro. Since this font is not freely available, the cowplot themes use the default R font, which for most graphic devices is Helvetica. All themes have a font_family argument that you can use to customize the font for your own use.

-
-

-Basic use of plot themes

-

The theme theme_half_open() (or equivalently, theme_cowplot()) provides a classical plot appearance with two axis lines and no background grid. This theme works for most types of graphs, but it is most appropriate for scatter plots and line graphs.

-
-library(ggplot2)
-library(cowplot)
-
-p <- ggplot(mtcars, aes(disp, mpg)) + geom_point()
-
-p + theme_half_open() # identical to theme_cowplot()
-
+

The cowplot package provides a consistent set of plot themes that +cover a wide range of use cases. To see these themes in action, check +out the book Fundamentals +of Data Visualization, which uses them throughout. However, +note that the figures in the book use the font Myriad Pro. Since this +font is not freely available, the cowplot themes use the default R font, +which for most graphic devices is Helvetica. All themes have a +font_family argument that you can use to customize the font +for your own use.

+
+

Basic use of plot themes +

+

The theme theme_half_open() (or equivalently, +theme_cowplot()) provides a classical plot appearance with +two axis lines and no background grid. This theme works for most types +of graphs, but it is most appropriate for scatter plots and line +graphs.

+
+library(ggplot2)
+library(cowplot)
+
+p <- ggplot(mtcars, aes(disp, mpg)) + geom_point()
+
+p + theme_half_open() # identical to theme_cowplot()

-

If you like a background grid, you can add it via the standard ggplot2 theme options. Alternatively, you can use the cowplot function background_grid(). This function needs to be placed after the theme call because the theme call overrides all previous theme settings.

-
-p +
-  theme_half_open() +
-  background_grid() # always place this after the theme
-
+

If you like a background grid, you can add it via the standard +ggplot2 theme options. Alternatively, you can use the cowplot function +background_grid(). This function needs to be placed after +the theme call because the theme call overrides all previous theme +settings.

+
+p +
+  theme_half_open() +
+  background_grid() # always place this after the theme

-

If you prefer a minimal appearance with grid and without axis lines, use theme_minimal_grid().

- +

If you prefer a minimal appearance with grid and without axis lines, +use theme_minimal_grid().

+

-

All themes can be further customized. For example, the default font size is 14 point, which works well for figures that are 5 to 8 inches wide. For smaller figures, you may want to use 12 point. Also, we can modify the color of the grid lines for theme_minimal_grid().

-
-p +
-  theme_minimal_grid(
-    font_size = 12,
-    color = "grey70"
-  )
-
+

All themes can be further customized. For example, the default font +size is 14 point, which works well for figures that are 5 to 8 inches +wide. For smaller figures, you may want to use 12 point. Also, we can +modify the color of the grid lines for +theme_minimal_grid().

+
+p +
+  theme_minimal_grid(
+    font_size = 12,
+    color = "grey70"
+  )

-
-

-Choosing themes in the context of the plot

-

When choosing a plot theme, you should always pay attention to how it works for your specific plot. For example, if you are making a bar plot, theme_half_open() generates awkward floating bars because of ggplot2’s automatic axis expansion (i.e., the x axis line does not lie at y = 0). I consider such plots to be ugly.

-
-p <- ggplot(mtcars, aes(factor(cyl))) +
-  geom_bar(fill = "#56B4E9", alpha = 0.8) +
-  theme_half_open()
-
-stamp_ugly(p)
-
+
+

Choosing themes in the context of the plot +

+

When choosing a plot theme, you should always pay attention to how it +works for your specific plot. For example, if you are making a bar plot, +theme_half_open() generates awkward floating bars because +of ggplot2’s automatic axis expansion (i.e., the x axis line does not +lie at y = 0). I consider such plots to be ugly.

+
+p <- ggplot(mtcars, aes(factor(cyl))) +
+  geom_bar(fill = "#56B4E9", alpha = 0.8) +
+  theme_half_open()
+
+stamp_ugly(p)

-

We can fix this problem by suppressing the axis expansion at the lower end.

-
-p <- ggplot(mtcars, aes(factor(cyl))) +
-  geom_bar(fill = "#56B4E9", alpha = 0.8) +
-  scale_y_continuous(
-    # don't expand y scale at the lower end
-    expand = expansion(mult = c(0, 0.05))
-  )
-
-p + theme_half_open()
-
+

We can fix this problem by suppressing the axis expansion at the +lower end.

+
+p <- ggplot(mtcars, aes(factor(cyl))) +
+  geom_bar(fill = "#56B4E9", alpha = 0.8) +
+  scale_y_continuous(
+    # don't expand y scale at the lower end
+    expand = expansion(mult = c(0, 0.05))
+  )
+
+p + theme_half_open()

-

Bar plots also tend to look awkward on background grids, and I would recommend against this use.

- +

Bar plots also tend to look awkward on background grids, and I would +recommend against this use.

+

-

Instead, you can use theme_minimal_hgrid(), which only draws horizontal grid lines.

- +

Instead, you can use theme_minimal_hgrid(), which only +draws horizontal grid lines.

+

-

If you make a flipped bar plot with horizontal bars, you may instead want vertical grid lines, which you obtain with theme_minimal_vgrid().

- +

If you make a flipped bar plot with horizontal bars, you may instead +want vertical grid lines, which you obtain with +theme_minimal_vgrid().

+

-
-

-Faceting

-

You need to pay special attention when faceting. A theme may look just fine for a single plot but work poorly in a faceted plot. As an example, consider what happens when we facet with theme_half_open().

-
-p <- ggplot(mtcars, aes(disp, mpg)) +
-  facet_wrap(~factor(cyl)) +
-  geom_point() +
-  theme_half_open(12)
-
-stamp_ugly(p)
-
+
+

Faceting +

+

You need to pay special attention when faceting. A theme may look +just fine for a single plot but work poorly in a faceted plot. As an +example, consider what happens when we facet with +theme_half_open().

+
+p <- ggplot(mtcars, aes(disp, mpg)) +
+  facet_wrap(~factor(cyl)) +
+  geom_point() +
+  theme_half_open(12)
+
+stamp_ugly(p)

-

The three facets don’t visually separate, because ggplot2 does not repeat the y axis line for each facet. We can improve the situation by drawing a border around each panel, either via standard ggplot2 theme calls or using the convenience function panel_border(). As with background_grid(), this function always has to be placed after the theme.

-
-p + panel_border()  # always place this after the theme
-
+

The three facets don’t visually separate, because ggplot2 does not +repeat the y axis line for each facet. We can improve the situation by +drawing a border around each panel, either via standard ggplot2 theme +calls or using the convenience function panel_border(). As +with background_grid(), this function always has to be +placed after the theme.

+
+p + panel_border()  # always place this after the theme

-

In this particular case, maybe using both a panel border and a background grid is the best option.

-
-p + 
-  panel_border() +
-  background_grid()
-
+

In this particular case, maybe using both a panel border and a +background grid is the best option.

+

-
-

-Empty themes

-

The two themes theme_map() and theme_nothing() provide stripped-down themes without axes. theme_map() is similar to theme_void() from ggplot2 in that it retains the plot title, subtitle, caption, and legends, and simply removes axis ticks, lines, labels, and gridlines. All settings are matched to the other cowplot themes, so that you can mix plots using theme_map() and the other cowplot themes and they will look consistent.

-

To demonstrate how these themes work and how they interact with the other themes provided, let’s first make a standard scatter plot with title, subtitle, caption, and legend.

-
-p <- ggplot(mtcars, aes(disp, mpg, color = wt)) +
-  geom_point() +
-  labs(
-    title = "Fuel efficiency in cars",
-    subtitle = "Bigger and more powerful cars are less efficient",
-    caption = "Motor Trend, 1974"
-  )
-
-p + theme_cowplot(12)
-
+
+

Empty themes +

+

The two themes theme_map() and +theme_nothing() provide stripped-down themes without axes. +theme_map() is similar to theme_void() from +ggplot2 in that it retains the plot title, subtitle, caption, and +legends, and simply removes axis ticks, lines, labels, and gridlines. +All settings are matched to the other cowplot themes, so that you can +mix plots using theme_map() and the other cowplot themes +and they will look consistent.

+

To demonstrate how these themes work and how they interact with the +other themes provided, let’s first make a standard scatter plot with +title, subtitle, caption, and legend.

+
+p <- ggplot(mtcars, aes(disp, mpg, color = wt)) +
+  geom_point() +
+  labs(
+    title = "Fuel efficiency in cars",
+    subtitle = "Bigger and more powerful cars are less efficient",
+    caption = "Motor Trend, 1974"
+  )
+
+p + theme_cowplot(12)

The same plot looks as follows with theme_map().

-
-p + theme_map(12)
-
+
+p + theme_map(12)

-

Notice how all elements that have been retained look the same between this plot and the previous one.

-

If we draw the same plot with theme_nothing(), then everything except the plot panel is removed, including titles and legends.

-
-p + theme_nothing()
-
+

Notice how all elements that have been retained look the same between +this plot and the previous one.

+

If we draw the same plot with theme_nothing(), then +everything except the plot panel is removed, including titles and +legends.

+

-

This theme is used by ggdraw() and plot_grid() for the enclosing drawing canvas.

+

This theme is used by ggdraw() and +plot_grid() for the enclosing drawing canvas.

@@ -268,11 +302,13 @@

-

Site built with pkgdown 1.6.0.

+

+

Site built with pkgdown 2.0.7.

@@ -281,5 +317,7 @@

+ + diff --git a/docs/articles/themes_files/figure-html/unnamed-chunk-10-1.png b/docs/articles/themes_files/figure-html/unnamed-chunk-10-1.png index 38b894c..57817ed 100644 Binary files a/docs/articles/themes_files/figure-html/unnamed-chunk-10-1.png and b/docs/articles/themes_files/figure-html/unnamed-chunk-10-1.png differ diff --git a/docs/articles/themes_files/figure-html/unnamed-chunk-11-1.png b/docs/articles/themes_files/figure-html/unnamed-chunk-11-1.png index 67f24ba..b9b59c8 100644 Binary files a/docs/articles/themes_files/figure-html/unnamed-chunk-11-1.png and b/docs/articles/themes_files/figure-html/unnamed-chunk-11-1.png differ diff --git a/docs/articles/themes_files/figure-html/unnamed-chunk-12-1.png b/docs/articles/themes_files/figure-html/unnamed-chunk-12-1.png index 170c655..e876e88 100644 Binary files a/docs/articles/themes_files/figure-html/unnamed-chunk-12-1.png and b/docs/articles/themes_files/figure-html/unnamed-chunk-12-1.png differ diff --git a/docs/articles/themes_files/figure-html/unnamed-chunk-13-1.png b/docs/articles/themes_files/figure-html/unnamed-chunk-13-1.png index 9b8c5e4..a0551c5 100644 Binary files a/docs/articles/themes_files/figure-html/unnamed-chunk-13-1.png and b/docs/articles/themes_files/figure-html/unnamed-chunk-13-1.png differ diff --git a/docs/articles/themes_files/figure-html/unnamed-chunk-14-1.png b/docs/articles/themes_files/figure-html/unnamed-chunk-14-1.png index f26b3de..5ad9404 100644 Binary files a/docs/articles/themes_files/figure-html/unnamed-chunk-14-1.png and b/docs/articles/themes_files/figure-html/unnamed-chunk-14-1.png differ diff --git a/docs/articles/themes_files/figure-html/unnamed-chunk-15-1.png b/docs/articles/themes_files/figure-html/unnamed-chunk-15-1.png index b2dfd5d..788aff3 100644 Binary files a/docs/articles/themes_files/figure-html/unnamed-chunk-15-1.png and b/docs/articles/themes_files/figure-html/unnamed-chunk-15-1.png differ diff --git a/docs/articles/themes_files/figure-html/unnamed-chunk-16-1.png b/docs/articles/themes_files/figure-html/unnamed-chunk-16-1.png index 02a72e5..7486d0a 100644 Binary files a/docs/articles/themes_files/figure-html/unnamed-chunk-16-1.png and b/docs/articles/themes_files/figure-html/unnamed-chunk-16-1.png differ diff --git a/docs/articles/themes_files/figure-html/unnamed-chunk-2-1.png b/docs/articles/themes_files/figure-html/unnamed-chunk-2-1.png index e47b976..f18b691 100644 Binary files a/docs/articles/themes_files/figure-html/unnamed-chunk-2-1.png and b/docs/articles/themes_files/figure-html/unnamed-chunk-2-1.png differ diff --git a/docs/articles/themes_files/figure-html/unnamed-chunk-3-1.png b/docs/articles/themes_files/figure-html/unnamed-chunk-3-1.png index 4f722a2..c5c28f0 100644 Binary files a/docs/articles/themes_files/figure-html/unnamed-chunk-3-1.png and b/docs/articles/themes_files/figure-html/unnamed-chunk-3-1.png differ diff --git a/docs/articles/themes_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/themes_files/figure-html/unnamed-chunk-4-1.png index 591c2cc..d4888e6 100644 Binary files a/docs/articles/themes_files/figure-html/unnamed-chunk-4-1.png and b/docs/articles/themes_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/themes_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/themes_files/figure-html/unnamed-chunk-5-1.png index ed260e8..981be92 100644 Binary files a/docs/articles/themes_files/figure-html/unnamed-chunk-5-1.png and b/docs/articles/themes_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/themes_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/themes_files/figure-html/unnamed-chunk-6-1.png index 1116e53..bcba7d3 100644 Binary files a/docs/articles/themes_files/figure-html/unnamed-chunk-6-1.png and b/docs/articles/themes_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/themes_files/figure-html/unnamed-chunk-7-1.png b/docs/articles/themes_files/figure-html/unnamed-chunk-7-1.png index 3d2d3b6..4f21e1b 100644 Binary files a/docs/articles/themes_files/figure-html/unnamed-chunk-7-1.png and b/docs/articles/themes_files/figure-html/unnamed-chunk-7-1.png differ diff --git a/docs/articles/themes_files/figure-html/unnamed-chunk-8-1.png b/docs/articles/themes_files/figure-html/unnamed-chunk-8-1.png index 33fd132..d695f23 100644 Binary files a/docs/articles/themes_files/figure-html/unnamed-chunk-8-1.png and b/docs/articles/themes_files/figure-html/unnamed-chunk-8-1.png differ diff --git a/docs/articles/themes_files/figure-html/unnamed-chunk-9-1.png b/docs/articles/themes_files/figure-html/unnamed-chunk-9-1.png index 1486f3b..9734c1a 100644 Binary files a/docs/articles/themes_files/figure-html/unnamed-chunk-9-1.png and b/docs/articles/themes_files/figure-html/unnamed-chunk-9-1.png differ diff --git a/docs/authors.html b/docs/authors.html index fdf4de1..e9a98ef 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -1,74 +1,12 @@ - - - - - - - -Authors • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Authors and Citation • cowplot - - + + - - - -
-
-
- -
+
- @@ -164,22 +107,20 @@

Authors

-
- +
- - + + diff --git a/docs/index.html b/docs/index.html index 08e477d..4d05508 100644 --- a/docs/index.html +++ b/docs/index.html @@ -33,6 +33,8 @@ + +
- - -
+
-
-

-cowplot 1.1.1 Unreleased -

-
    -
  • Make sure tests don’t fail if vdiffr is missing.
  • -
-
-
-

-cowplot 1.1.0 2020-09-08 -

-
+
+ +
+

Breaking changes

In many ways, cowplot now behaves more appropriately and plays nicer with the R environment and other R packages. However, this means that several breaking changes were introduced:

-
    -
  • The default ggplot2 theme is no longer changed upon loading. You can add theme_set(theme_cowplot()) to your code to restore the old behavior.
  • +
    • The default ggplot2 theme is no longer changed upon loading. You can add theme_set(theme_cowplot()) to your code to restore the old behavior.
    • The package ggplot2 needs to be loaded separately from cowplot, it is not automatically attached.
    • All themes now use parameters font_size and font_family. Previously, theme_nothing() and theme_map() used base_size and base_family.
    • -
    • The function cowplot::ggsave() was renamed to cowplot::ggsave2(), so that the ggplot2 version of ggsave() is no longer masked by the cowplot version.
    • -
    -

    Other breaking changes:

    -
      -
    • The defaults for save_plot() were changed somewhat. This may require adjustment if you have code depending on it.
    • -
    +
  • The function cowplot::ggsave() was renamed to cowplot::ggsave2(), so that the ggplot2 version of ggsave() is no longer masked by the cowplot version.
  • +

Other breaking changes: - The defaults for save_plot() were changed somewhat. This may require adjustment if you have code depending on it.

-
-

-New features

-
    -
  • New functions rectangle_key_glyph() and circle_key_glyph() make it possible to generate customized legend glyphs.
  • +
    +

    New features

    + -
    -
    -

    -Minor changes

    -
      -
    • Minor tweaks to various legend layout parameters so that legends look better as the underlying theme font size is changed.
    • +
    • Expanded functions for extracting plot components from ggplots via get_plot_component() and several wrapper functions for getting titles, axes, panels, and so on. This also lets get_panel() extract from plots with more than one panel. get_panel_component() allows you to further extract components like geoms from the plot panel (@malcolmbarrett, #111).
    • +
    +
    +

    Minor changes

    +
    • Minor tweaks to various legend layout parameters so that legends look better as the underlying theme font size is changed.
    • Various minor fixes to theme_cowplot() and derived themes.
    • Change background_grid() defaults so they match the new grid themes.
    • Renamed plot_to_gtable() to as_gtable().
    • All functions now understand both spellings of color/colour.
    • get_legend() now returns NULL if there is no legend, instead of raising an error.
    • -
    -
    -
-
-

-cowplot 0.9.4 2019-01-08 -

-
    -
  • Fix CRAN check errors
  • -
-
-
-

-cowplot 0.9.3 2018-07-15 -

-
    -
  • Fix regression tests to work with ggplot2 3.0.0
  • -
-
-
-

-cowplot 0.9.2 2017-12-17 -

-
    -
  • Rewritten cowplot::ggsave function that calls ggplot2::ggsave
  • +
+
+
+ +
  • Fix CRAN check errors
  • +
+
+ +
  • Fix regression tests to work with ggplot2 3.0.0
  • +
+
+ +
  • Rewritten cowplot::ggsave function that calls ggplot2::ggsave
  • More robust handling of R graphics device weirdness/plots popping up in the wrong places
  • -
-
-
-

-cowplot 0.9.1 2017-11-16 -

-
    -
  • Make examples and vignettes fail gracefully when magick package is not installed
  • -
-
-
-

-cowplot 0.9.0 2017-11-16 -

-
+
+ +
  • Make examples and vignettes fail gracefully when magick package is not installed
  • +
+
+ +
  • Added a theme for maps, theme_map(). Code provided by Spencer Fox, https://github.com/sjfox.
  • Added axis_canvas() function and related functions to make marginal plots and plot annotations simpler
  • Now export the plot_to_gtable function which converts most anything into a gtable for further use with cowplot
  • Added inherit.aes = FALSE to draw functions where needed
  • Added examples to various draw functions
  • Added draw_image() function to draw images onto plots
  • -
-
-
-

-cowplot 0.8.0 2017-07-30 -

-
    -
  • The function plot_grid can now also handle base-R (graphics) plots. Code provided by https://github.com/flying-sheep.
  • -
  • More sophisticated plot alignments of complex plots are now possible. Code provided by Spencer Fox, https://github.com/sjfox.
  • -
  • Plot labels can now be styled. In particular, they follow the theme settings, e.g. if the theme uses a different font than default. This closes issue #37.
  • -
  • The positioning of plot labels in plot_grid can now be controlled with additional position parameters label_x and label_y. This closes issue #32.
  • -
  • Problems with elements from globally set themes leaking into the plot-grid background have been fixed. This closes issues #60, #63, #66.
  • -
-
-
-

-cowplot 0.7.0 2016-10-28 -

-
    -
  • This version of cowplot has been prepared for the upcoming release of ggplot2 2.2.0. As a result of this upcoming switch, the function switch_axis_position() has been removed. Alternative axes will be natively supported by ggplot2 2.2.0.
  • +
+
+ +
  • The function plot_grid can now also handle base-R (graphics) plots. Code provided by https://github.com/flying-sheep.
  • +
  • More sophisticated plot alignments of complex plots are now possible. Code provided by Spencer Fox, https://github.com/sjfox.
  • +
  • Plot labels can now be styled. In particular, they follow the theme settings, e.g. if the theme uses a different font than default. This closes issue #37.
  • +
  • The positioning of plot labels in plot_grid can now be controlled with additional position parameters label_x and label_y. This closes issue #32.
  • +
  • Problems with elements from globally set themes leaking into the plot-grid background have been fixed. This closes issues #60, #63, #66.
  • +
+
+ +
  • This version of cowplot has been prepared for the upcoming release of ggplot2 2.2.0. As a result of this upcoming switch, the function switch_axis_position() has been removed. Alternative axes will be natively supported by ggplot2 2.2.0.
  • As of this version, cowplot requires R >= 3.3.0. This dependency was added because R 3.3 fixes a critical problem with lists of units.
  • -
-
-
-

-cowplot 0.6.3 2016-09-30 -

-
+
+ + -
-
-

-cowplot 0.6.2 2016-04-20 -

-
    -
  • Updated plot_grid vignette so the tutorial on aligning plots of different types works again. This stopped working at some point and was removed from 0.6.1.
  • -
-
-
-

-cowplot 0.6.1 2016-03-06 -

-
    -
  • Added new convenience function draw_figure_label() to label figures with labels such as “Figure 1”.
  • +
+
+ +
  • Updated plot_grid vignette so the tutorial on aligning plots of different types works again. This stopped working at some point and was removed from 0.6.1.
  • +
+
+ +
  • Added new convenience function draw_figure_label() to label figures with labels such as “Figure 1”.
  • Fixes in switch_axis_position() so that rotated axis labels work.
  • Fix missing axis lines in ggplot2 2.1
  • -
-
-
-

-cowplot 0.6.0 2015-12-19 -

-

Major changes:

-
    -
  • Now requires ggplot2 version 2.0.0 or higher. Use cowplot 0.5.0 with older versions of ggplot2.
  • -
  • Because of the dependency on ggplot2 2.0.0, the default design is changed. No more bold face for axis labels
  • -
  • Add auto-generation of labels in plot_grid()
  • -
  • Add vignettes describing plot annotations and shared legends among plots
  • -
-
-
-

-cowplot 0.5.0 2015-07-01 -

-

Major changes:

-
    -
  • Fix label positioning in plot_grid() so it is not affected by the scale parameter
  • -
  • Add draw_label() function which can draw both text and plotmath expressions
  • -
  • Add parameters hjust and vjust to plot_grid() to allow fine-tuning of label position
  • -
  • Add annotations underneath plot, via add_sub() function
  • -
-

Other changes:

-
    -
  • Improve vignettes
  • -
-
-
-

-cowplot 0.4.0 2015-06-14 -

-

Major changes:

-
    -
  • Added a function switch_axis_position() which can move/copy the x and/or y axis of a plot to the other side
  • -
  • plot_grid() can now align graphs
  • -
  • plot_grid() can now make grids with varying column widths and row heights
  • -
-

Other changes:

-
    -
  • Various improvements in the documentation
  • -
  • Code has been separated into multiple files for easier maintenance
  • -
-
-
-

-cowplot 0.3.1 2015-06-04 -

+
+
+ +

Major changes: - Now requires ggplot2 version 2.0.0 or higher. Use cowplot 0.5.0 with older versions of ggplot2. - Because of the dependency on ggplot2 2.0.0, the default design is changed. No more bold face for axis labels - Add auto-generation of labels in plot_grid() - Add vignettes describing plot annotations and shared legends among plots

+
+
+ +

Major changes: - Fix label positioning in plot_grid() so it is not affected by the scale parameter - Add draw_label() function which can draw both text and plotmath expressions - Add parameters hjust and vjust to plot_grid() to allow fine-tuning of label position - Add annotations underneath plot, via add_sub() function

+

Other changes: - Improve vignettes

+
+
+ +

Major changes: - Added a function switch_axis_position() which can move/copy the x and/or y axis of a plot to the other side - plot_grid() can now align graphs - plot_grid() can now make grids with varying column widths and row heights

+

Other changes: - Various improvements in the documentation - Code has been separated into multiple files for easier maintenance

+
+
+

Fix Vignette title

-
-

-cowplot 0.3.0 2015-06-03 -

+
+

First complete implementation ready for initial release

+
-
- +
- - + + diff --git a/docs/pkgdown.css b/docs/pkgdown.css index 1273238..80ea5b8 100644 --- a/docs/pkgdown.css +++ b/docs/pkgdown.css @@ -56,8 +56,10 @@ img.icon { float: right; } -img { +/* Ensure in-page images don't run outside their container */ +.contents img { max-width: 100%; + height: auto; } /* Fix bug in bootstrap (only seen in firefox) */ @@ -78,11 +80,10 @@ dd { /* Section anchors ---------------------------------*/ a.anchor { - margin-left: -30px; - display:inline-block; - width: 30px; - height: 30px; - visibility: hidden; + display: none; + margin-left: 5px; + width: 20px; + height: 20px; background-image: url(./link.svg); background-repeat: no-repeat; @@ -90,17 +91,15 @@ a.anchor { background-position: center center; } -.hasAnchor:hover a.anchor { - visibility: visible; -} - -@media (max-width: 767px) { - .hasAnchor:hover a.anchor { - visibility: hidden; - } +h1:hover .anchor, +h2:hover .anchor, +h3:hover .anchor, +h4:hover .anchor, +h5:hover .anchor, +h6:hover .anchor { + display: inline-block; } - /* Fixes for fixed navbar --------------------------*/ .contents h1, .contents h2, .contents h3, .contents h4 { @@ -264,31 +263,26 @@ table { /* Syntax highlighting ---------------------------------------------------- */ -pre { - word-wrap: normal; - word-break: normal; - border: 1px solid #eee; -} - -pre, code { +pre, code, pre code { background-color: #f8f8f8; color: #333; } +pre, pre code { + white-space: pre-wrap; + word-break: break-all; + overflow-wrap: break-word; +} -pre code { - overflow: auto; - word-wrap: normal; - white-space: pre; +pre { + border: 1px solid #eee; } -pre .img { +pre .img, pre .r-plt { margin: 5px 0; } -pre .img img { +pre .img img, pre .r-plt img { background-color: #fff; - display: block; - height: auto; } code a, pre a { @@ -305,9 +299,8 @@ a.sourceLine:hover { .kw {color: #264D66;} /* keyword */ .co {color: #888888;} /* comment */ -.message { color: black; font-weight: bolder;} -.error { color: orange; font-weight: bolder;} -.warning { color: #6A0366; font-weight: bolder;} +.error {font-weight: bolder;} +.warning {font-weight: bolder;} /* Clipboard --------------------------*/ @@ -365,3 +358,27 @@ mark { content: ""; } } + +/* Section anchors --------------------------------- + Added in pandoc 2.11: https://github.com/jgm/pandoc-templates/commit/9904bf71 +*/ + +div.csl-bib-body { } +div.csl-entry { + clear: both; +} +.hanging-indent div.csl-entry { + margin-left:2em; + text-indent:-2em; +} +div.csl-left-margin { + min-width:2em; + float:left; +} +div.csl-right-inline { + margin-left:2em; + padding-left:1em; +} +div.csl-indent { + margin-left: 2em; +} diff --git a/docs/pkgdown.js b/docs/pkgdown.js index 7e7048f..6f0eee4 100644 --- a/docs/pkgdown.js +++ b/docs/pkgdown.js @@ -80,7 +80,7 @@ $(document).ready(function() { var copyButton = ""; - $(".examples, div.sourceCode").addClass("hasCopyButton"); + $("div.sourceCode").addClass("hasCopyButton"); // Insert copy buttons: $(copyButton).prependTo(".hasCopyButton"); @@ -91,7 +91,7 @@ // Initialize clipboard: var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { text: function(trigger) { - return trigger.parentNode.textContent; + return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); } }); diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index eefea4e..dd4d2d9 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -1,6 +1,13 @@ -pandoc: 2.10.1 -pkgdown: 1.6.0 +pandoc: 3.1.1 +pkgdown: 2.0.7 pkgdown_sha: ~ -articles: [] -last_built: 2020-12-15T17:50Z +articles: + aligning_plots: aligning_plots.html + drawing_with_on_plots: drawing_with_on_plots.html + introduction: introduction.html + mixing_plot_frameworks: mixing_plot_frameworks.html + plot_grid: plot_grid.html + shared_legends: shared_legends.html + themes: themes.html +last_built: 2023-12-15T04:39Z diff --git a/docs/reference/Rplot001.png b/docs/reference/Rplot001.png index 72955e8..73ca673 100644 Binary files a/docs/reference/Rplot001.png and b/docs/reference/Rplot001.png differ diff --git a/docs/reference/Rplot002.png b/docs/reference/Rplot002.png index ce00d20..7b856e1 100644 Binary files a/docs/reference/Rplot002.png and b/docs/reference/Rplot002.png differ diff --git a/docs/reference/Rplot003.png b/docs/reference/Rplot003.png index 7741a05..5a15069 100644 Binary files a/docs/reference/Rplot003.png and b/docs/reference/Rplot003.png differ diff --git a/docs/reference/Rplot004.png b/docs/reference/Rplot004.png index 063d56d..4a05cdc 100644 Binary files a/docs/reference/Rplot004.png and b/docs/reference/Rplot004.png differ diff --git a/docs/reference/Rplot005.png b/docs/reference/Rplot005.png index 0016438..2f8916c 100644 Binary files a/docs/reference/Rplot005.png and b/docs/reference/Rplot005.png differ diff --git a/docs/reference/Rplot006.png b/docs/reference/Rplot006.png index b74d674..482d049 100644 Binary files a/docs/reference/Rplot006.png and b/docs/reference/Rplot006.png differ diff --git a/docs/reference/Rplot007.png b/docs/reference/Rplot007.png index cc0544f..0473ff9 100644 Binary files a/docs/reference/Rplot007.png and b/docs/reference/Rplot007.png differ diff --git a/docs/reference/Rplot008.png b/docs/reference/Rplot008.png index 877a034..a98ba49 100644 Binary files a/docs/reference/Rplot008.png and b/docs/reference/Rplot008.png differ diff --git a/docs/reference/Rplot009.png b/docs/reference/Rplot009.png index 260c113..4e062b8 100644 Binary files a/docs/reference/Rplot009.png and b/docs/reference/Rplot009.png differ diff --git a/docs/reference/add_sub-1.png b/docs/reference/add_sub-1.png index 410a1bb..2bd9e67 100644 Binary files a/docs/reference/add_sub-1.png and b/docs/reference/add_sub-1.png differ diff --git a/docs/reference/add_sub-2.png b/docs/reference/add_sub-2.png index ee225d6..3b6bac3 100644 Binary files a/docs/reference/add_sub-2.png and b/docs/reference/add_sub-2.png differ diff --git a/docs/reference/add_sub-3.png b/docs/reference/add_sub-3.png index f7275c0..f681da6 100644 Binary files a/docs/reference/add_sub-3.png and b/docs/reference/add_sub-3.png differ diff --git a/docs/reference/add_sub-4.png b/docs/reference/add_sub-4.png index 8326ab4..1dce478 100644 Binary files a/docs/reference/add_sub-4.png and b/docs/reference/add_sub-4.png differ diff --git a/docs/reference/add_sub.html b/docs/reference/add_sub.html index 9cdce11..4077b6c 100644 --- a/docs/reference/add_sub.html +++ b/docs/reference/add_sub.html @@ -1,78 +1,15 @@ - - - - - - - -Add annotation underneath a plot — add_sub • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Add annotation underneath a plot — add_sub • cowplot - - - - - - - - - - - + + - - - -
-
- -
- -
+

This function can add an arbitrary label or mathematical expression underneath the plot, similar to the sub parameter in base R. It is mostly superseded now by the -caption argument to ggplot2::labs(), and it is recommended to use caption instead of +caption argument to ggplot2::labs(), and it is recommended to use caption instead of add_sub() whenever possible.

-
add_sub(
-  plot,
-  label,
-  x = 0.5,
-  y = 0.5,
-  hjust = 0.5,
-  vjust = 0.5,
-  vpadding = grid::unit(1, "lines"),
-  fontfamily = "",
-  fontface = "plain",
-  color = "black",
-  size = 14,
-  angle = 0,
-  lineheight = 0.9,
-  colour
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
plot

A ggplot object or gtable object derived from a ggplot object.

label

The label with which the plot should be annotated. Can be a plotmath expression.

x

The x position of the label

y

The y position of the label

hjust

Horizontal justification

vjust

Vertical justification

vpadding

Vertical padding. The total vertical space added to the label, given in grid +

+
add_sub(
+  plot,
+  label,
+  x = 0.5,
+  y = 0.5,
+  hjust = 0.5,
+  vjust = 0.5,
+  vpadding = grid::unit(1, "lines"),
+  fontfamily = "",
+  fontface = "plain",
+  color = "black",
+  size = 14,
+  angle = 0,
+  lineheight = 0.9,
+  colour
+)
+
+ +
+

Arguments

+
plot
+

A ggplot object or gtable object derived from a ggplot object.

+ + +
label
+

The label with which the plot should be annotated. Can be a plotmath expression.

+ + +
x
+

The x position of the label

+ + +
y
+

The y position of the label

+ + +
hjust
+

Horizontal justification

+ + +
vjust
+

Vertical justification

+ + +
vpadding
+

Vertical padding. The total vertical space added to the label, given in grid units. By default, this is added equally above and below the label. However, by changing the -y and vjust parameters, this can be changed.

fontfamily

The font family

fontface

The font face ("plain", "bold", etc.)

color, colour

Text color

size

Point size of text

angle

Angle at which text is drawn

lineheight

Line height of text

- -

Value

- -

A gtable object holding the modified plot.

-

Details

+y and vjust parameters, this can be changed.

+ + +
fontfamily
+

The font family

+ +
fontface
+

The font face ("plain", "bold", etc.)

+ + +
color, colour
+

Text color

+ + +
size
+

Point size of text

+ + +
angle
+

Angle at which text is drawn

+ + +
lineheight
+

Line height of text

+ +
+
+

Value

+ + +

A gtable object holding the modified plot.

+
+
+

Details

The exact location where the label is placed is controlled by the parameters x, y, hjust, and vjust. By default, all these parameters are set to 0.5, which places the label @@ -266,55 +190,59 @@

Details case with x, y-values outside the range 0-1 are allowed. In particular, for sufficiently large values of y, the label will eventually be located inside the plot panel.

+

-

Examples

-
library(ggplot2) -theme_set(theme_half_open()) -p1 <- ggplot(mtcars, aes(mpg, disp)) + geom_line(colour = "blue") + background_grid(minor='none') -ggdraw(add_sub(p1, "This is an annotation.\nAnnotations can span multiple lines.")) -
-# You can also do this repeatedly. -p2 <- add_sub(p1, "This formula has no relevance here:", y = 0, vjust = 0) -p3 <- add_sub(p2, expression(paste(a^2+b^2, " = ", c^2))) -ggdraw(p3) -
-#This code also works with faceted plots: -plot.iris <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) + - geom_point() + facet_grid(. ~ Species) + stat_smooth(method = "lm") + - background_grid(major = 'y', minor = "none") + # add thin horizontal lines - panel_border() # and a border around each panel -p2 <- add_sub(plot.iris, "Annotation underneath a faceted plot, left justified.", x = 0, hjust = 0) -
#> `geom_smooth()` using formula 'y ~ x'
ggdraw(p2) -
-# Finally, it is possible to move the annotation inside of the plot if desired. -ggdraw(add_sub(p1, "Annotation inside plot", vpadding=grid::unit(0, "lines"), - y = 6, x = 0.03, hjust = 0)) -
+
+

Examples

+
library(ggplot2)
+theme_set(theme_half_open())
+p1 <- ggplot(mtcars, aes(mpg, disp)) + geom_line(colour = "blue") + background_grid(minor='none')
+ggdraw(add_sub(p1, "This is an annotation.\nAnnotations can span multiple lines."))
+
+
+# You can also do this repeatedly.
+p2 <- add_sub(p1, "This formula has no relevance here:", y  = 0, vjust = 0)
+p3 <- add_sub(p2, expression(paste(a^2+b^2, " = ", c^2)))
+ggdraw(p3)
+
+
+#This code also works with faceted plots:
+plot.iris <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
+  geom_point() + facet_grid(. ~ Species) + stat_smooth(method = "lm") +
+  background_grid(major = 'y', minor = "none") + # add thin horizontal lines
+  panel_border() # and a border around each panel
+p2 <- add_sub(plot.iris, "Annotation underneath a faceted plot, left justified.", x = 0, hjust = 0)
+#> `geom_smooth()` using formula = 'y ~ x'
+ggdraw(p2)
+
+
+# Finally, it is possible to move the annotation inside of the plot if desired.
+ggdraw(add_sub(p1, "Annotation inside plot", vpadding=grid::unit(0, "lines"),
+       y = 6, x = 0.03, hjust = 0))
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/align_margin-1.png b/docs/reference/align_margin-1.png index d043c84..0fa2a42 100644 Binary files a/docs/reference/align_margin-1.png and b/docs/reference/align_margin-1.png differ diff --git a/docs/reference/align_margin.html b/docs/reference/align_margin.html index 59e17df..a70d541 100644 --- a/docs/reference/align_margin.html +++ b/docs/reference/align_margin.html @@ -1,82 +1,19 @@ - - - - - - - -Align multiple plots along a specified margin — align_margin • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Align multiple plots along a specified margin — align_margin • cowplot - - - - - - - - - - - + + - - - -
-
- -
- -
+

The function aligns the dimensions of multiple plots along a specified axis, and is solely a helper function -for align_plots() to reduce redundancy. Each element of the sizes +for align_plots() to reduce redundancy. Each element of the sizes list corresponds to the dimensions of a plot being aligned. They should be vectors created from calls to grob$heights or grob$widths depending on whether you are aligning vertically or horizontally. -The list of dimensions is generated automatically by the align_plots() function, but see examples. +The list of dimensions is generated automatically by the align_plots() function, but see examples. If the same number of elements exist for all plots for the specified margin, the function will align individual elements on the margin. Otherwise, it aligns the plot by adding white space to plot margins so that all margins have the same dimensions.

-
align_margin(sizes, margin_to_align, greedy = TRUE)
- -

Arguments

- - - - - - - - - - - - - - -
sizes

list of dimensions for each plot being aligned. Each element of list -obtained by a call to grob$heights or grob$widths (see example).

margin_to_align

string either "first" or "last" for which part of plot area should be aligned. +

+
align_margin(sizes, margin_to_align, greedy = TRUE)
+
+ +
+

Arguments

+
sizes
+

list of dimensions for each plot being aligned. Each element of list +obtained by a call to grob$heights or grob$widths (see example).

+ + +
margin_to_align
+

string either "first" or "last" for which part of plot area should be aligned. If vertically aligning, "first" aligns left margin and "last" aligns right margin. If horizontally aligning -"first" aligns top margin and "last" aligns bottom margin.

greedy

if TRUE, alignment is always achieved by adjusting the most extreme +"first" aligns top margin and "last" aligns bottom margin.

+ + +
greedy
+

if TRUE, alignment is always achieved by adjusting the most extreme margin; if FALSE, and the number of dimensions for each plot are the same, then -all dimensions are jointly adjusted.

- - -

Examples

-
library(ggplot2) - -# Example for how to utilize, though align_plots() does this internally and automatically -df <- data.frame( - x = 1:10, y1 = 1:10, y2 = (1:10)^2, y3 = (1:10)^3 -) - -p1 <- ggplot(df, aes(x, y1)) + geom_point() -p2 <- ggplot(df, aes(x, y2)) + geom_point() -p3 <- ggplot(df, aes(x, y3)) + geom_point() -plots <- list(p1, p2, p3) -grobs <- lapply(plots, as_grob) -plot_widths <- lapply(grobs, function(x) {x$widths}) -# Aligning the left margins of all plots -aligned_widths <- align_margin(plot_widths, "first") -# Aligning the right margins of all plots as well -aligned_widths <- align_margin(aligned_widths, "last") -# Setting the dimensions of plots to the aligned dimensions -for (i in seq_along(plots)) { - grobs[[i]]$widths <- aligned_widths[[i]] -} -# Draw aligned plots -plot_grid(plotlist = grobs, ncol = 1) -
+all dimensions are jointly adjusted.

+ +
+ +
+

Examples

+
library(ggplot2)
+
+# Example for how to utilize, though align_plots() does this internally and automatically
+df <- data.frame(
+  x = 1:10, y1 = 1:10, y2 = (1:10)^2, y3 = (1:10)^3
+)
+
+p1 <- ggplot(df, aes(x, y1)) + geom_point()
+p2 <- ggplot(df, aes(x, y2)) + geom_point()
+p3 <- ggplot(df, aes(x, y3)) + geom_point()
+plots <- list(p1, p2, p3)
+grobs <- lapply(plots, as_grob)
+plot_widths <- lapply(grobs, function(x) {x$widths})
+# Aligning the left margins of all plots
+aligned_widths <- align_margin(plot_widths, "first")
+# Aligning the right margins of all plots as well
+aligned_widths <- align_margin(aligned_widths, "last")
+# Setting the dimensions of plots to the aligned dimensions
+for (i in seq_along(plots)) {
+  grobs[[i]]$widths <- aligned_widths[[i]]
+}
+# Draw aligned plots
+plot_grid(plotlist = grobs, ncol = 1)
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/align_plots-1.png b/docs/reference/align_plots-1.png index a49ca20..fe53c48 100644 Binary files a/docs/reference/align_plots-1.png and b/docs/reference/align_plots-1.png differ diff --git a/docs/reference/align_plots.html b/docs/reference/align_plots.html index 9d454e1..33e0f38 100644 --- a/docs/reference/align_plots.html +++ b/docs/reference/align_plots.html @@ -1,80 +1,17 @@ - - - - - - - -Align multiple plots vertically and/or horizontally — align_plots • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Align multiple plots vertically and/or horizontally — align_plots • cowplot - - - - - - - - - - - - + + - - -
-
- -
- -
+
@@ -163,93 +85,93 @@

Align multiple plots vertically and/or horizontally

Align the plot area of multiple plots. Inputs are a list of plots plus alignment parameters. Horizontal or vertical alignment or both are possible. In the simplest case the function will align all elements of each plot, but it can handle more complex cases as long as the axis parameter is defined. In this case, -alignment is done through a call to align_margin(). The function align_plots is called by the plot_grid() function +alignment is done through a call to align_margin(). The function align_plots is called by the plot_grid() function and is usually not called directly, though direct calling of the function is useful if plots with multiple y-axes are desired (see example).

-
align_plots(
-  ...,
-  plotlist = NULL,
-  align = c("none", "h", "v", "hv"),
-  axis = c("none", "l", "r", "t", "b", "lr", "tb", "tblr"),
-  greedy = TRUE
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - -
...

List of plots to be aligned.

plotlist

(optional) List of plots to display. Alternatively, the plots can be provided -individually as the first n arguments of the function align_plots (see plot_grid examples).

align

(optional) Specifies whether graphs in the grid should be horizontally ("h") or -vertically ("v") aligned. Options are align="none" (default), "hv" (align in both directions), "h", and "v".

axis

(optional) Specifies whether graphs should be aligned by the left ("l"), right ("r"), top ("t"), or bottom ("b") -margins. Options are axis="none" (default), or a string of any combination of "l", "r", "t", and/or "b" in any order -(e.g. axis="tblr" or axis="rlbt" for aligning all margins)

greedy

(optional) Defines the alignment policy when alignment axes are specified via the -axis option. greedy = TRUE tries to always align by adjusting the outmost margin. greedy = FALSE -aligns all columns/rows in the gtable if possible.

+
+
align_plots(
+  ...,
+  plotlist = NULL,
+  align = c("none", "h", "v", "hv"),
+  axis = c("none", "l", "r", "t", "b", "lr", "tb", "tblr"),
+  greedy = TRUE
+)
+
+ +
+

Arguments

+
...
+

List of plots to be aligned.

+ + +
plotlist
+

(optional) List of plots to display. Alternatively, the plots can be provided +individually as the first n arguments of the function align_plots (see plot_grid examples).

+ +
align
+

(optional) Specifies whether graphs in the grid should be horizontally ("h") or +vertically ("v") aligned. Options are align="none" (default), "hv" (align in both directions), "h", and "v".

-

Examples

-
library(ggplot2) -p1 <- ggplot(mpg, aes(manufacturer, hwy)) + stat_summary(fun.y="median", geom = "bar") + - theme_half_open() + - theme(axis.text.x = element_text(angle = 45, hjust = 1, vjust= 1)) -
#> Warning: `fun.y` is deprecated. Use `fun` instead.
p2 <- ggplot(mpg, aes(manufacturer, displ)) + geom_point(color="red") + - scale_y_continuous(position = "right") + - theme_half_open() + theme(axis.text.x = element_blank()) +
axis
+

(optional) Specifies whether graphs should be aligned by the left ("l"), right ("r"), top ("t"), or bottom ("b") +margins. Options are axis="none" (default), or a string of any combination of "l", "r", "t", and/or "b" in any order +(e.g. axis="tblr" or axis="rlbt" for aligning all margins)

-# manually align and plot on top of each other -aligned_plots <- align_plots(p1, p2, align="hv", axis="tblr") -# Note: In most cases two y-axes should not be used, but this example -# illustrates how one could accomplish it. -ggdraw(aligned_plots[[1]]) + draw_plot(aligned_plots[[2]]) -
+
greedy
+

(optional) Defines the alignment policy when alignment axes are specified via the +axis option. greedy = TRUE tries to always align by adjusting the outmost margin. greedy = FALSE +aligns all columns/rows in the gtable if possible.

+ +
+ +
+

Examples

+
library(ggplot2)
+
+p1 <- ggplot(mpg, aes(manufacturer, hwy)) + stat_summary(fun.y="median", geom = "bar") +
+  theme_half_open() +
+  theme(axis.text.x = element_text(angle = 45, hjust = 1, vjust= 1))
+#> Warning: The `fun.y` argument of `stat_summary()` is deprecated as of ggplot2 3.3.0.
+#>  Please use the `fun` argument instead.
+p2 <- ggplot(mpg, aes(manufacturer, displ)) + geom_point(color="red") +
+  scale_y_continuous(position = "right") +
+  theme_half_open() + theme(axis.text.x = element_blank())
+
+# manually align and plot on top of each other
+aligned_plots <- align_plots(p1, p2, align="hv", axis="tblr")
+
+# Note: In most cases two y-axes should not be used, but this example
+# illustrates how one could accomplish it.
+ggdraw(aligned_plots[[1]]) + draw_plot(aligned_plots[[2]])
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/as_grob-1.png b/docs/reference/as_grob-1.png index 07968c4..700bf9f 100644 Binary files a/docs/reference/as_grob-1.png and b/docs/reference/as_grob-1.png differ diff --git a/docs/reference/as_grob.html b/docs/reference/as_grob.html index 70ba118..c167adc 100644 --- a/docs/reference/as_grob.html +++ b/docs/reference/as_grob.html @@ -1,78 +1,15 @@ - - - - - - - -Convert a base plot or a ggplot2 plot into a grob — as_grob • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Convert a base plot or a ggplot2 plot into a grob — as_grob • cowplot - - - - - - - - - - - - + + - - -
-
- -
- -
+
@@ -164,57 +86,55 @@

Convert a base plot or a ggplot2 plot into a grob

generates a base R plot, or a trellis object.

-
as_grob(plot, device = NULL)
- -

Arguments

- - - - - - - - - - -
plot

The plot to convert

device

A function that creates an appropriate null device. See set_null_device() -for details. If set to NULL, will use the cowplot-wide default.

- - -

Examples

-
library(grid) -x <- 1:10 -y <- (1:10)^2 - -p <- ~plot(x, y) -grid.newpage() -grid.draw(as_grob(p)) -
+
+
as_grob(plot, device = NULL)
+
+ +
+

Arguments

+
plot
+

The plot to convert

+ + +
device
+

A function that creates an appropriate null device. See set_null_device() +for details. If set to NULL, will use the cowplot-wide default.

+ +
+ +
+

Examples

+
library(grid)
+x <- 1:10
+y <- (1:10)^2
+
+p <- ~plot(x, y)
+grid.newpage()
+grid.draw(as_grob(p))
+
+
+
+
-
- +

- - + + diff --git a/docs/reference/as_gtable.html b/docs/reference/as_gtable.html index acb5f98..db54b2c 100644 --- a/docs/reference/as_gtable.html +++ b/docs/reference/as_gtable.html @@ -1,77 +1,14 @@ - - - - - - - -Convert plot or other graphics object into a gtable — as_gtable • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Convert plot or other graphics object into a gtable — as_gtable • cowplot - - - - - - - - - - - - + + - - -
-
- -
- -
+
@@ -162,50 +84,46 @@

Convert plot or other graphics object into a gtable

object (grob), a recorded R base plot, or a function that generates an R base plot.

-
as_gtable(plot)
-
-plot_to_gtable(plot)
- -

Arguments

- - - - - - -
plot

The plot or other graphics object to convert into a gtable. Here, plot can be -any object handled by as_grob().

+
+
as_gtable(plot)
+
+plot_to_gtable(plot)
+
-

Details

+
+

Arguments

+
plot
+

The plot or other graphics object to convert into a gtable. Here, plot can be +any object handled by as_grob().

+
+
+

Details

To convert ggplot plots, the function needs to use a null graphics device. This can be set -with set_null_device().

+with set_null_device().

+
+
-
- +
- - + + diff --git a/docs/reference/axis_canvas-1.png b/docs/reference/axis_canvas-1.png index 068bc95..20c71ea 100644 Binary files a/docs/reference/axis_canvas-1.png and b/docs/reference/axis_canvas-1.png differ diff --git a/docs/reference/axis_canvas-2.png b/docs/reference/axis_canvas-2.png index efcdf1a..be04e62 100644 Binary files a/docs/reference/axis_canvas-2.png and b/docs/reference/axis_canvas-2.png differ diff --git a/docs/reference/axis_canvas-3.png b/docs/reference/axis_canvas-3.png index cf52581..39f491f 100644 Binary files a/docs/reference/axis_canvas-3.png and b/docs/reference/axis_canvas-3.png differ diff --git a/docs/reference/axis_canvas.html b/docs/reference/axis_canvas.html index cfae0b9..9ba6054 100644 --- a/docs/reference/axis_canvas.html +++ b/docs/reference/axis_canvas.html @@ -1,81 +1,18 @@ - - - - - - - -Generates a canvas onto which one can draw axis-like objects. — axis_canvas • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Generates a canvas onto which one can draw axis-like objects. — axis_canvas • cowplot - - - - - - - - - - - - + + - - -
-
- -
- -
+
-

This function takes an existing ggplot2 plot and copies one or both of the axis into a new plot. -The main idea is to use this in conjunction with insert_xaxis_grob() or insert_yaxis_grob() to +

This function takes an existing ggplot2 plot and copies one or both of the axis into a new plot. +The main idea is to use this in conjunction with insert_xaxis_grob() or insert_yaxis_grob() to draw custom axis-like objects or margin annotations. Importantly, while this function works for both continuous and discrete scales, notice that discrete scales are converted into continuous scales in the returned axis canvas. The levels of the discrete scale are placed at continuous values of @@ -170,133 +92,138 @@

Generates a canvas onto which one can draw axis-like objects.

scale.

-
axis_canvas(
-  plot,
-  axis = "y",
-  data = NULL,
-  mapping = aes(),
-  xlim = NULL,
-  ylim = NULL,
-  coord_flip = FALSE
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
plot

The plot defining the x and/or y axis range for the axis canvas.

axis

Specifies which axis to copy from plot. Can be "x", "y", or "xy".

data

(optional) Data to be displayed in this layer.

mapping

(optional) Aesthetic mapping to be used in this layer.

xlim

(optional) Vector of two numbers specifying the limits of the x axis. Ignored -if the x axis is copied over from plot.

ylim

(optional) Vector of two numbers specifying the limits of the y axis. Ignored -if the y axis is copied over from plot.

coord_flip

(optional) If true, flips the coordinate system and applies x limits to -the y axis and vice versa. Useful in combination with ggplot2's coord_flip() function.

- - -

Examples

-
# annotate line graphs with labels on the right -library(dplyr) -
#> -#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’: -#> -#> filter, lag
#> The following objects are masked from ‘package:base’: -#> -#> intersect, setdiff, setequal, union
library(tidyr) -library(ggplot2) -theme_set(theme_half_open()) -x <- seq(0, 10, .1) -d <- data.frame(x, - linear = x, - squared = x*x/5, - cubed = x*x*x/25) %>% - gather(fun, y, -x) - -pmain <- ggplot(d, aes(x, y, group = fun)) + geom_line() + - scale_x_continuous(expand = c(0, 0)) - -paxis <- axis_canvas(pmain, axis = "y") + - geom_text(data = filter(d, x == max(x)), aes(y = y, label = paste0(" ", fun)), - x = 0, hjust = 0, vjust = 0.5) -ggdraw(insert_yaxis_grob(pmain, paxis, grid::unit(.25, "null"))) -
-# discrete scale with integrated color legend -pmain <- ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) + - geom_violin(trim = FALSE) + guides(fill = "none") + - scale_x_discrete(labels = NULL) + - theme_minimal() - -label_data <- data.frame(x = 1:nlevels(iris$Species), - Species = levels(iris$Species)) -paxis <- axis_canvas(pmain, axis = "x", data = label_data, mapping = aes(x = x)) + - geom_tile(aes(fill = Species, y = 0.5), width = 0.9, height = 0.3) + - geom_text(aes(label = Species, y = 0.5), hjust = 0.5, vjust = 0.5, size = 11/.pt) -ggdraw(insert_xaxis_grob(pmain, paxis, grid::unit(.07, "null"), - position = "bottom")) -
-# add marginal density distributions to plot -pmain <- ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species)) + geom_point() - -xdens <- axis_canvas(pmain, axis = "x") + - geom_density(data=iris, aes(x=Sepal.Length, fill=Species), alpha=0.7, size=.2) - -# need to set `coord_flip = TRUE` if you plan to use `coord_flip()` -ydens <- axis_canvas(pmain, axis = "y", coord_flip = TRUE) + - geom_density(data=iris, aes(x=Sepal.Width, fill=Species), alpha=0.7, size=.2) + - coord_flip() +
+
axis_canvas(
+  plot,
+  axis = "y",
+  data = NULL,
+  mapping = aes(),
+  xlim = NULL,
+  ylim = NULL,
+  coord_flip = FALSE
+)
+
-p1 <- insert_xaxis_grob(pmain, xdens, grid::unit(.2, "null"), position = "top") -p2 <- insert_yaxis_grob(p1, ydens, grid::unit(.2, "null"), position = "right") -ggdraw(p2) -
+
+

Arguments

+
plot
+

The plot defining the x and/or y axis range for the axis canvas.

+ + +
axis
+

Specifies which axis to copy from plot. Can be "x", "y", or "xy".

+ + +
data
+

(optional) Data to be displayed in this layer.

+ + +
mapping
+

(optional) Aesthetic mapping to be used in this layer.

+ + +
xlim
+

(optional) Vector of two numbers specifying the limits of the x axis. Ignored +if the x axis is copied over from plot.

+ + +
ylim
+

(optional) Vector of two numbers specifying the limits of the y axis. Ignored +if the y axis is copied over from plot.

+ + +
coord_flip
+

(optional) If true, flips the coordinate system and applies x limits to +the y axis and vice versa. Useful in combination with ggplot2's coord_flip() function.

+ +
+ +
+

Examples

+
# annotate line graphs with labels on the right
+library(dplyr)
+#> 
+#> Attaching package: ‘dplyr’
+#> The following objects are masked from ‘package:stats’:
+#> 
+#>     filter, lag
+#> The following objects are masked from ‘package:base’:
+#> 
+#>     intersect, setdiff, setequal, union
+library(tidyr)
+library(ggplot2)
+theme_set(theme_half_open())
+x <- seq(0, 10, .1)
+d <- data.frame(x,
+                linear = x,
+                squared = x*x/5,
+                cubed = x*x*x/25) %>%
+  gather(fun, y, -x)
+
+pmain <- ggplot(d, aes(x, y, group = fun)) + geom_line()  +
+  scale_x_continuous(expand = c(0, 0))
+
+paxis <- axis_canvas(pmain, axis = "y") +
+  geom_text(data = filter(d, x == max(x)), aes(y = y, label = paste0(" ", fun)),
+            x = 0, hjust = 0, vjust = 0.5)
+ggdraw(insert_yaxis_grob(pmain, paxis, grid::unit(.25, "null")))
+
+
+# discrete scale with integrated color legend
+pmain <- ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) +
+  geom_violin(trim = FALSE) + guides(fill = "none") +
+  scale_x_discrete(labels = NULL) +
+  theme_minimal()
+
+label_data <- data.frame(x = 1:nlevels(iris$Species),
+                         Species = levels(iris$Species))
+paxis <- axis_canvas(pmain, axis = "x", data = label_data, mapping = aes(x = x)) +
+  geom_tile(aes(fill = Species, y = 0.5), width = 0.9, height = 0.3) +
+  geom_text(aes(label = Species, y = 0.5), hjust = 0.5, vjust = 0.5, size = 11/.pt)
+ggdraw(insert_xaxis_grob(pmain, paxis, grid::unit(.07, "null"),
+                         position = "bottom"))
+
+
+# add marginal density distributions to plot
+pmain <- ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species)) + geom_point()
+
+xdens <- axis_canvas(pmain, axis = "x") +
+  geom_density(data=iris, aes(x=Sepal.Length, fill=Species), alpha=0.7, size=.2)
+#> Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
+#>  Please use `linewidth` instead.
+
+# need to set `coord_flip = TRUE` if you plan to use `coord_flip()`
+ydens <- axis_canvas(pmain, axis = "y", coord_flip = TRUE) +
+  geom_density(data=iris, aes(x=Sepal.Width, fill=Species), alpha=0.7, size=.2) +
+  coord_flip()
+
+p1 <- insert_xaxis_grob(pmain, xdens, grid::unit(.2, "null"), position = "top")
+p2 <- insert_yaxis_grob(p1, ydens, grid::unit(.2, "null"), position = "right")
+ggdraw(p2)
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/background_grid-1.png b/docs/reference/background_grid-1.png index d6eea65..f94c730 100644 Binary files a/docs/reference/background_grid-1.png and b/docs/reference/background_grid-1.png differ diff --git a/docs/reference/background_grid.html b/docs/reference/background_grid.html index fad29eb..16b3529 100644 --- a/docs/reference/background_grid.html +++ b/docs/reference/background_grid.html @@ -1,77 +1,14 @@ - - - - - - - -Add/modify/remove the background grid in a ggplot2 plot — background_grid • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Add/modify/remove the background grid in a ggplot2 plot — background_grid • cowplot - - - - - - - - - - - - + + - - -
-
- -
- -
+

This function provides a simple way to set the background grid in ggplot2. It -doesn't do anything that can't be done just the same with theme(). However, it simplifies +doesn't do anything that can't be done just the same with theme(). However, it simplifies creation of the most commonly needed variations.

-
background_grid(
-  major = c("xy", "x", "y", "only_minor", "none"),
-  minor = c("none", "xy", "x", "y"),
-  size.major = 0.5,
-  size.minor = 0.2,
-  color.major = "grey85",
-  color.minor = "grey85",
-  colour.major,
-  colour.minor
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - -
major

Specifies along which axes you would like to plot major grid lines. Options are "xy", "x", -"y", "none".

minor

Specifies along which axes you would like to plot minor grid lines. Options are "xy", "x", -"y", "none".

size.major

Size of the major grid lines.

size.minor

Size of the minor grid lines.

color.major, colour.major

Color of the major grid lines.

color.minor, colour.minor

Color of the minor grid lines.

- -

Details

+
+
background_grid(
+  major = c("xy", "x", "y", "only_minor", "none"),
+  minor = c("none", "xy", "x", "y"),
+  size.major = 0.5,
+  size.minor = 0.2,
+  color.major = "grey85",
+  color.minor = "grey85",
+  colour.major,
+  colour.minor
+)
+
-

Note: This function completely overwrites all background grid settings of the current theme. If that -is not what you want, you may be better off using theme() directly.

+
+

Arguments

+
major
+

Specifies along which axes you would like to plot major grid lines. Options are "xy", "x", +"y", "none".

+ + +
minor
+

Specifies along which axes you would like to plot minor grid lines. Options are "xy", "x", +"y", "none".

+ + +
size.major
+

Size of the major grid lines.

-

Examples

-
library(ggplot2) -ggplot(iris, aes(Sepal.Length, Sepal.Width)) + - geom_point() + - theme_half_open() + - background_grid() -
+
size.minor
+

Size of the minor grid lines.

+ + +
color.major, colour.major
+

Color of the major grid lines.

+ + +
color.minor, colour.minor
+

Color of the minor grid lines.

+ +
+
+

Details

+

Note: This function completely overwrites all background grid settings of the current theme. If that +is not what you want, you may be better off using theme() directly.

+
+ +
+

Examples

+
library(ggplot2)
+
+ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
+ geom_point() +
+ theme_half_open() +
+ background_grid()
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/cowplot-package.html b/docs/reference/cowplot-package.html new file mode 100644 index 0000000..f41b0e1 --- /dev/null +++ b/docs/reference/cowplot-package.html @@ -0,0 +1,130 @@ + +Streamlined Plot Theme and Plot Annotations for 'ggplot2' — cowplot-package • cowplot + + +
+
+ + + +
+
+ + +
+

Provides various features that help with creating publication-quality +figures with 'ggplot2', such as a set of themes, functions to align +plots and arrange them into complex compound figures, and functions +that make it easy to annotate plots and or mix plots with images. The +package was originally written for internal use in the Wilke lab, +hence the name (Claus O. Wilke's plot package). It has also been used +extensively in the book Fundamentals of Data Visualization.

+
+ + + +
+

Author

+

Maintainer: Claus O. Wilke wilke@austin.utexas.edu (ORCID)

+
+ +
+ +
+ + +
+ +
+

Site built with pkgdown 2.0.7.

+
+ +
+ + + + + + + + diff --git a/docs/reference/draw_figure_label-1.png b/docs/reference/draw_figure_label-1.png index a20b007..55b4f39 100644 Binary files a/docs/reference/draw_figure_label-1.png and b/docs/reference/draw_figure_label-1.png differ diff --git a/docs/reference/draw_figure_label-2.png b/docs/reference/draw_figure_label-2.png index 72c1c4a..b60dbbe 100644 Binary files a/docs/reference/draw_figure_label-2.png and b/docs/reference/draw_figure_label-2.png differ diff --git a/docs/reference/draw_figure_label-3.png b/docs/reference/draw_figure_label-3.png index a3db234..96f31fd 100644 Binary files a/docs/reference/draw_figure_label-3.png and b/docs/reference/draw_figure_label-3.png differ diff --git a/docs/reference/draw_figure_label-4.png b/docs/reference/draw_figure_label-4.png index fcb16c0..3cd2fad 100644 Binary files a/docs/reference/draw_figure_label-4.png and b/docs/reference/draw_figure_label-4.png differ diff --git a/docs/reference/draw_figure_label-5.png b/docs/reference/draw_figure_label-5.png index 778fac0..6b9907f 100644 Binary files a/docs/reference/draw_figure_label-5.png and b/docs/reference/draw_figure_label-5.png differ diff --git a/docs/reference/draw_figure_label.html b/docs/reference/draw_figure_label.html index b9ad2ba..bb0852a 100644 --- a/docs/reference/draw_figure_label.html +++ b/docs/reference/draw_figure_label.html @@ -1,77 +1,14 @@ - - - - - - - -Add a label to a figure — draw_figure_label • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Add a label to a figure — draw_figure_label • cowplot - + + - - - -
-
- -
- -
+
@@ -162,101 +84,105 @@

Add a label to a figure

one pane. The function is similar to draw_plot_label.

-
draw_figure_label(
-  label,
-  position = c("top.left", "top", "top.right", "bottom.left", "bottom", "bottom.right"),
-  size,
-  fontface,
-  ...
-)
+
+
draw_figure_label(
+  label,
+  position = c("top.left", "top", "top.right", "bottom.left", "bottom", "bottom.right"),
+  size,
+  fontface,
+  ...
+)
+
-

Arguments

- - - - - - - - - - - - - - - - - - - - - - -
label

Label to be drawn

position

Position of the label, can be one of "top.left", "top", "top.right", "bottom.left", "bottom", "bottom.right". Default is "top.left"

size

(optional) Size of the label to be drawn. Default is the text size of the current theme

fontface

(optional) Font face of the label to be drawn. Default is the font face of the current theme

...

other arguments passed to draw_plot_label

+
+

Arguments

+
label
+

Label to be drawn

-

See also

- -

Author

+
position
+

Position of the label, can be one of "top.left", "top", "top.right", "bottom.left", "bottom", "bottom.right". Default is "top.left"

+ + +
size
+

(optional) Size of the label to be drawn. Default is the text size of the current theme

-

Ulrik Stervbo (ulrik.stervbo @ gmail.com)

-

Examples

-
library(ggplot2) -df <- data.frame( - x = 1:10, y1 = 1:10, y2 = (1:10)^2, y3 = (1:10)^3, y4 = (1:10)^4 -) +
fontface
+

(optional) Font face of the label to be drawn. Default is the font face of the current theme

-p1 <- ggplot(df, aes(x, y1)) + geom_point() -p2 <- ggplot(df, aes(x, y2)) + geom_point() -p3 <- ggplot(df, aes(x, y3)) + geom_point() -p4 <- ggplot(df, aes(x, y4)) + geom_point() -# Create a simple grid -p <- plot_grid(p1, p2, p3, p4, align = 'hv') +
...
+

other arguments passed to draw_plot_label

+ +
+
+

See also

+ +
+
+

Author

+

Ulrik Stervbo (ulrik.stervbo @ gmail.com)

+
-# Default font size and position -p + draw_figure_label(label = "Figure 1") -
-# Different position and font size -p + draw_figure_label(label = "Figure 1", position = "bottom.right", size = 10) -
-# Using bold font face -p + draw_figure_label(label = "Figure 1", fontface = "bold") -
-# Making the label red and slanted -p + draw_figure_label(label = "Figure 1", angle = -45, colour = "red") -
-# Labeling an individual plot -ggdraw(p2) + draw_figure_label(label = "Figure 1", position = "bottom.right", size = 10) -
-
+
+

Examples

+
library(ggplot2)
+df <- data.frame(
+  x = 1:10, y1 = 1:10, y2 = (1:10)^2, y3 = (1:10)^3, y4 = (1:10)^4
+)
+
+p1 <- ggplot(df, aes(x, y1)) + geom_point()
+p2 <- ggplot(df, aes(x, y2)) + geom_point()
+p3 <- ggplot(df, aes(x, y3)) + geom_point()
+p4 <- ggplot(df, aes(x, y4)) + geom_point()
+
+# Create a simple grid
+p <- plot_grid(p1, p2, p3, p4, align = 'hv')
+
+# Default font size and position
+p + draw_figure_label(label = "Figure 1")
+
+
+# Different position and font size
+p + draw_figure_label(label = "Figure 1", position = "bottom.right", size = 10)
+
+
+# Using bold font face
+p + draw_figure_label(label = "Figure 1", fontface = "bold")
+
+
+# Making the label red and slanted
+p + draw_figure_label(label = "Figure 1", angle = -45, colour = "red")
+
+
+# Labeling an individual plot
+ggdraw(p2) + draw_figure_label(label = "Figure 1", position = "bottom.right", size = 10)
+
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/draw_grob.html b/docs/reference/draw_grob.html index 9fb0764..32ac3db 100644 --- a/docs/reference/draw_grob.html +++ b/docs/reference/draw_grob.html @@ -1,76 +1,13 @@ - - - - - - - -Draw a grob. — draw_grob • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Draw a grob. — draw_grob • cowplot - - + + - - -
-
- -
- -
+
@@ -160,96 +82,94 @@

Draw a grob.

0 to 1, and the point (0, 0) is in the lower left corner of the canvas.

-
draw_grob(
-  grob,
-  x = 0,
-  y = 0,
-  width = 1,
-  height = 1,
-  scale = 1,
-  clip = "inherit",
-  hjust = 0,
-  vjust = 0,
-  halign = 0.5,
-  valign = 0.5
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
grob

The grob to place.

x

The x location of the grob. (Left side if hjust = 0.)

y

The y location of the grob. (Bottom side if vjust = 0.)

width

Width of the grob.

height

Height of the grob.

scale

Scales the grob relative to the rectangle defined by x, y, width, height. A setting -of scale = 1 indicates no scaling.

clip

Set to "on" to clip the grob or "inherit" to not clip. Note that clipping doesn't always work as -expected, due to limitations of the grid graphics system.

hjust, vjust

Horizontal and vertical justification relative to x.

halign, valign

Horizontal and vertical justification of the grob inside -the box.

- - -

Examples

-
# A grid grob (here a blue circle) -g <- grid::circleGrob(gp = grid::gpar(fill = "blue")) -# place into the middle of the plotting area, at a scale of 50% -ggdraw() + draw_grob(g, scale = 0.5) -
+
+
draw_grob(
+  grob,
+  x = 0,
+  y = 0,
+  width = 1,
+  height = 1,
+  scale = 1,
+  clip = "inherit",
+  hjust = 0,
+  vjust = 0,
+  halign = 0.5,
+  valign = 0.5
+)
+
+ +
+

Arguments

+
grob
+

The grob to place.

+ + +
x
+

The x location of the grob. (Left side if hjust = 0.)

+ + +
y
+

The y location of the grob. (Bottom side if vjust = 0.)

+ + +
width
+

Width of the grob.

+ + +
height
+

Height of the grob.

+ + +
scale
+

Scales the grob relative to the rectangle defined by x, y, width, height. A setting +of scale = 1 indicates no scaling.

+ + +
clip
+

Set to "on" to clip the grob or "inherit" to not clip. Note that clipping doesn't always work as +expected, due to limitations of the grid graphics system.

+ + +
hjust, vjust
+

Horizontal and vertical justification relative to x.

+ + +
halign, valign
+

Horizontal and vertical justification of the grob inside +the box.

+ +
+ +
+

Examples

+
# A grid grob (here a blue circle)
+g <- grid::circleGrob(gp = grid::gpar(fill = "blue"))
+# place into the middle of the plotting area, at a scale of 50%
+ggdraw() + draw_grob(g, scale = 0.5)
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/draw_image-1.png b/docs/reference/draw_image-1.png index 12c4dc7..81ff0a9 100644 Binary files a/docs/reference/draw_image-1.png and b/docs/reference/draw_image-1.png differ diff --git a/docs/reference/draw_image-2.png b/docs/reference/draw_image-2.png index db1fb80..d994f14 100644 Binary files a/docs/reference/draw_image-2.png and b/docs/reference/draw_image-2.png differ diff --git a/docs/reference/draw_image-3.png b/docs/reference/draw_image-3.png index 0672c0b..454e70c 100644 Binary files a/docs/reference/draw_image-3.png and b/docs/reference/draw_image-3.png differ diff --git a/docs/reference/draw_image-4.png b/docs/reference/draw_image-4.png index 02372f8..930d7f4 100644 Binary files a/docs/reference/draw_image-4.png and b/docs/reference/draw_image-4.png differ diff --git a/docs/reference/draw_image.html b/docs/reference/draw_image.html index e1df047..a7e5999 100644 --- a/docs/reference/draw_image.html +++ b/docs/reference/draw_image.html @@ -1,77 +1,14 @@ - - - - - - - -Draw an image — draw_image • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Draw an image — draw_image • cowplot - - - - - - - - - - - - + + - - -
-
- -
- -
+
@@ -162,145 +84,146 @@

Draw an image

package to work, and fails gracefully if that package is not installed.

-
draw_image(
-  image,
-  x = 0,
-  y = 0,
-  width = 1,
-  height = 1,
-  scale = 1,
-  clip = "inherit",
-  interpolate = TRUE,
-  hjust = 0,
-  vjust = 0,
-  halign = 0.5,
-  valign = 0.5
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
image

The image to place. Can be a file path, a URL, or a raw vector with image data, -as in magick::image_read(). Can also be an image previously created by magick::image_read() and -related functions.

x

The x location of the image. (Left side if hjust = 0.)

y

The y location of the image. (Bottom side if vjust = 0.)

width

Width of the image.

height

Height of the image.

scale

Scales the image relative to the rectangle defined by x, y, width, height. A setting -of scale = 1 indicates no scaling.

clip

Set to "on" to clip the image relative to the box into which it is draw (useful for scale > 1). -Note that clipping doesn't always work as expected, due to limitations of the grid graphics system.

interpolate

A logical value indicating whether to linearly interpolate the image -(the alternative is to use nearest-neighbour interpolation, which gives a more blocky result).

hjust, vjust

Horizontal and vertical justification relative to x.

halign, valign

Horizontal and vertical justification of the image inside -the box.

- - -

Examples

-
library(ggplot2) - -# Use image as plot background -p <- ggplot(iris, aes(x = Sepal.Length, fill = Species)) + - geom_density(alpha = 0.7) + - scale_y_continuous(expand = expansion(mult = c(0, 0.05))) + - theme_half_open(12) - -logo_file <- system.file("extdata", "logo.png", package = "cowplot") -ggdraw() + - draw_image( - logo_file, scale = .7 - ) + - draw_plot(p) -
-# Place in lower right corner -ggdraw() + - draw_image( - logo_file, scale = .3, x = 1, - hjust = 1, halign = 1, valign = 0 - ) + - draw_plot(p) -
-# Make grid with plot and image -cow_file <- system.file("extdata", "cow.jpg", package = "cowplot") -p2 <- ggdraw() + draw_image(cow_file, scale = 0.9) -plot_grid( - p + theme(legend.position = c(1, 1), legend.justification = c(1, 1)), - p2, - labels = "AUTO" -) -
-# Manipulate images and draw in plot coordinates -if (requireNamespace("magick", quietly = TRUE)){ - img <- magick::image_transparent( - magick::image_read(logo_file), - color = "white" - ) - img2 <- magick::image_negate(img) - ggplot(data.frame(x = 1:3, y = 1:3), aes(x, y)) + - geom_point(size = 3) + - geom_abline(slope = 1, intercept = 0, linetype = 2, color = "blue") + - draw_image(img , x = 1, y = 1, scale = .9) + - draw_image(img2, x = 2, y = 2, scale = .9) -} -
+
+
draw_image(
+  image,
+  x = 0,
+  y = 0,
+  width = 1,
+  height = 1,
+  scale = 1,
+  clip = "inherit",
+  interpolate = TRUE,
+  hjust = 0,
+  vjust = 0,
+  halign = 0.5,
+  valign = 0.5
+)
+
+ +
+

Arguments

+
image
+

The image to place. Can be a file path, a URL, or a raw vector with image data, +as in magick::image_read(). Can also be an image previously created by magick::image_read() and +related functions.

+ + +
x
+

The x location of the image. (Left side if hjust = 0.)

+ + +
y
+

The y location of the image. (Bottom side if vjust = 0.)

+ + +
width
+

Width of the image.

+ + +
height
+

Height of the image.

+ + +
scale
+

Scales the image relative to the rectangle defined by x, y, width, height. A setting +of scale = 1 indicates no scaling.

+ + +
clip
+

Set to "on" to clip the image relative to the box into which it is draw (useful for scale > 1). +Note that clipping doesn't always work as expected, due to limitations of the grid graphics system.

+ + +
interpolate
+

A logical value indicating whether to linearly interpolate the image +(the alternative is to use nearest-neighbour interpolation, which gives a more blocky result).

+ + +
hjust, vjust
+

Horizontal and vertical justification relative to x.

+ + +
halign, valign
+

Horizontal and vertical justification of the image inside +the box.

+ +
+ +
+

Examples

+
library(ggplot2)
+
+# Use image as plot background
+p <- ggplot(iris, aes(x = Sepal.Length, fill = Species)) +
+  geom_density(alpha = 0.7) +
+  scale_y_continuous(expand = expansion(mult = c(0, 0.05))) +
+  theme_half_open(12)
+
+logo_file <- system.file("extdata", "logo.png", package = "cowplot")
+ggdraw() +
+  draw_image(
+    logo_file, scale = .7
+  ) +
+  draw_plot(p)
+
+
+# Place in lower right corner
+ggdraw() +
+  draw_image(
+    logo_file, scale = .3, x = 1,
+    hjust = 1, halign = 1, valign = 0
+  ) +
+  draw_plot(p)
+
+
+# Make grid with plot and image
+cow_file <- system.file("extdata", "cow.jpg", package = "cowplot")
+p2 <- ggdraw() + draw_image(cow_file, scale = 0.9)
+plot_grid(
+  p + theme(legend.position = c(1, 1), legend.justification = c(1, 1)),
+  p2,
+  labels = "AUTO"
+)
+
+
+# Manipulate images and draw in plot coordinates
+if (requireNamespace("magick", quietly = TRUE)){
+  img <- magick::image_transparent(
+    magick::image_read(logo_file),
+    color = "white"
+  )
+  img2 <- magick::image_negate(img)
+  ggplot(data.frame(x = 1:3, y = 1:3), aes(x, y)) +
+    geom_point(size = 3) +
+    geom_abline(slope = 1, intercept = 0, linetype = 2, color = "blue") +
+    draw_image(img , x = 1, y = 1, scale = .9) +
+    draw_image(img2, x = 2, y = 2, scale = .9)
+}
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/draw_label-1.png b/docs/reference/draw_label-1.png index 392a593..4534c88 100644 Binary files a/docs/reference/draw_label-1.png and b/docs/reference/draw_label-1.png differ diff --git a/docs/reference/draw_label-2.png b/docs/reference/draw_label-2.png index bc9cb48..fe64ef9 100644 Binary files a/docs/reference/draw_label-2.png and b/docs/reference/draw_label-2.png differ diff --git a/docs/reference/draw_label-3.png b/docs/reference/draw_label-3.png index b8e531b..7f505ec 100644 Binary files a/docs/reference/draw_label-3.png and b/docs/reference/draw_label-3.png differ diff --git a/docs/reference/draw_label-4.png b/docs/reference/draw_label-4.png index b5ca84a..ebc6403 100644 Binary files a/docs/reference/draw_label-4.png and b/docs/reference/draw_label-4.png differ diff --git a/docs/reference/draw_label.html b/docs/reference/draw_label.html index 7daecc8..1b46a7d 100644 --- a/docs/reference/draw_label.html +++ b/docs/reference/draw_label.html @@ -1,77 +1,14 @@ - - - - - - - -Draw a text label or mathematical expression. — draw_label • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Draw a text label or mathematical expression. — draw_label • cowplot - - - - - - - - - - + + - - - - -
-
- -
- -
+
@@ -162,138 +84,141 @@

Draw a text label or mathematical expression.

on which coordinate system is desired (see examples).

-
draw_label(
-  label,
-  x = 0.5,
-  y = 0.5,
-  hjust = 0.5,
-  vjust = 0.5,
-  fontfamily = "",
-  fontface = "plain",
-  color = "black",
-  size = 14,
-  angle = 0,
-  lineheight = 0.9,
-  alpha = 1,
-  colour
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
label

String or plotmath expression to be drawn.

x

The x location (origin) of the label.

y

The y location (origin) of the label.

hjust

Horizontal justification. Default = 0.5 (centered on x). 0 = flush-left at x, 1 = flush-right.

vjust

Vertical justification. Default = 0.5 (centered on y). 0 = baseline at y, 1 = ascender at y.

fontfamily

The font family

fontface

The font face ("plain", "bold", etc.)

color, colour

Text color

size

Point size of text

angle

Angle at which text is drawn

lineheight

Line height of text

alpha

The alpha value of the text

- -

Details

+
+
draw_label(
+  label,
+  x = 0.5,
+  y = 0.5,
+  hjust = 0.5,
+  vjust = 0.5,
+  fontfamily = "",
+  fontface = "plain",
+  color = "black",
+  size = 14,
+  angle = 0,
+  lineheight = 0.9,
+  alpha = 1,
+  colour
+)
+
+ +
+

Arguments

+
label
+

String or plotmath expression to be drawn.

+ + +
x
+

The x location (origin) of the label.

+ + +
y
+

The y location (origin) of the label.

+ + +
hjust
+

Horizontal justification. Default = 0.5 (centered on x). 0 = flush-left at x, 1 = flush-right.

+ + +
vjust
+

Vertical justification. Default = 0.5 (centered on y). 0 = baseline at y, 1 = ascender at y.

+ + +
fontfamily
+

The font family

+ + +
fontface
+

The font face ("plain", "bold", etc.)

+ +
color, colour
+

Text color

+ + +
size
+

Point size of text

+ + +
angle
+

Angle at which text is drawn

+ + +
lineheight
+

Line height of text

+ + +
alpha
+

The alpha value of the text

+ +
+
+

Details

By default, the x and y coordinates specify the center of the text box. Set hjust = 0, vjust = 0 to specify the lower left corner, and other values of hjust and vjust for any other relative location you want to specify.

-

See also

- - - -

Examples

-
library(ggplot2) - -# setup plot and a label (regression description) -p <- ggplot(mtcars, aes(disp, mpg)) + - geom_line(color = "blue") + - theme_half_open() + - background_grid(minor = 'none') -out <- cor.test(mtcars$disp, mtcars$mpg, method = 'sp', exact = FALSE) -label <- substitute( - paste("Spearman ", rho, " = ", estimate, ", P = ", pvalue), - list(estimate = signif(out$estimate, 2), pvalue = signif(out$p.value, 2)) -) - -# Add label to plot, centered on {x,y} (in data coordinates) -p + draw_label(label, x = 300, y = 32) -
# Add label to plot in data coordinates, flush-left at x, baseline at y. -p + draw_label(label, x = 100, y = 30, hjust = 0, vjust = 0) -
-# Add labels via ggdraw. Uses ggdraw coordinates. -# ggdraw coordinates default to xlim = c(0, 1), ylim = c(0, 1). -ggdraw(p) + - draw_label("centered on 70% of x range,\n90% of y range", x = 0.7, y = 0.9) -
-ggdraw(p) + - draw_label("bottom left at (0, 0)", x = 0, y = 0, hjust = 0, vjust = 0) + - draw_label("top right at (1, 1)", x = 1, y = 1, hjust = 1, vjust = 1) + - draw_label("centered on (0.5, 0.5)", x = 0.5, y = 0.5, hjust = 0.5, vjust = 0.5) -
+
+
+

See also

+ +
+ +
+

Examples

+
library(ggplot2)
+
+# setup plot and a label (regression description)
+p <- ggplot(mtcars, aes(disp, mpg)) +
+  geom_line(color = "blue") +
+  theme_half_open() +
+  background_grid(minor = 'none')
+out <- cor.test(mtcars$disp, mtcars$mpg, method = 'sp', exact = FALSE)
+label <- substitute(
+  paste("Spearman ", rho, " = ", estimate, ", P = ", pvalue),
+  list(estimate = signif(out$estimate, 2), pvalue = signif(out$p.value, 2))
+)
+
+# Add label to plot, centered on {x,y} (in data coordinates)
+p + draw_label(label, x = 300, y = 32)
+
+# Add label to plot in data coordinates, flush-left at x, baseline at y.
+p + draw_label(label, x = 100, y = 30, hjust = 0, vjust = 0)
+
+
+# Add labels via ggdraw. Uses ggdraw coordinates.
+# ggdraw coordinates default to xlim = c(0, 1), ylim = c(0, 1).
+ggdraw(p) +
+  draw_label("centered on 70% of x range,\n90% of y range", x = 0.7, y = 0.9)
+
+
+ggdraw(p) +
+  draw_label("bottom left at (0, 0)", x = 0, y = 0, hjust = 0, vjust = 0) +
+  draw_label("top right at (1, 1)", x = 1, y = 1, hjust = 1, vjust = 1) +
+  draw_label("centered on (0.5, 0.5)", x = 0.5, y = 0.5, hjust = 0.5, vjust = 0.5)
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/draw_line.html b/docs/reference/draw_line.html index 97e2180..66725b6 100644 --- a/docs/reference/draw_line.html +++ b/docs/reference/draw_line.html @@ -1,75 +1,12 @@ - - - - - - - -Draw a line from connected points — draw_line • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Draw a line from connected points — draw_line • cowplot - - + + - - -
-
- -
- -
+
@@ -158,65 +80,65 @@

Draw a line from connected points

Provide a sequence of x values and accompanying y values to draw a line on a plot.

-
draw_line(x, y, ...)
- -

Arguments

- - - - - - - - - - - - - - -
x

Vector of x coordinates.

y

Vector of y coordinates.

...

geom_path parameters such as colour, alpha, size, etc.

- -

Details

+
+
draw_line(x, y, ...)
+
+ +
+

Arguments

+
x
+

Vector of x coordinates.

+ +
y
+

Vector of y coordinates.

+ + +
...
+

geom_path parameters such as colour, alpha, size, etc.

+ +
+
+

Details

This is a convenience function, providing a wrapper around ggplot2's geom_path.

-

See also

- - - -

Examples

-
ggdraw() + - draw_line( - x = c(0.2, 0.7, 0.7, 0.3), - y = c(0.1, 0.3, 0.9, 0.8), - color = "blue", size = 2 - ) -
+
+
+

See also

+ +
+ +
+

Examples

+
ggdraw() +
+  draw_line(
+    x = c(0.2, 0.7, 0.7, 0.3),
+    y = c(0.1, 0.3, 0.9, 0.8),
+    color = "blue", size = 2
+  )
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/draw_plot-1.png b/docs/reference/draw_plot-1.png index 474b82c..5263488 100644 Binary files a/docs/reference/draw_plot-1.png and b/docs/reference/draw_plot-1.png differ diff --git a/docs/reference/draw_plot.html b/docs/reference/draw_plot.html index 36238cd..f07a1a5 100644 --- a/docs/reference/draw_plot.html +++ b/docs/reference/draw_plot.html @@ -1,76 +1,13 @@ - - - - - - - -Draw a (sub)plot. — draw_plot • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Draw a (sub)plot. — draw_plot • cowplot - + + - - - -
-
- -
- -
+
@@ -160,94 +82,92 @@

Draw a (sub)plot.

0 to 1, and the point (0, 0) is in the lower left corner of the canvas.

-
draw_plot(
-  plot,
-  x = 0,
-  y = 0,
-  width = 1,
-  height = 1,
-  scale = 1,
-  hjust = 0,
-  vjust = 0,
-  halign = 0.5,
-  valign = 0.5
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
plot

The plot to place. Can be a ggplot2 plot, an arbitrary grob or gtable, -or a recorded base-R plot, as in as_grob().

x

The x location of the plot. (Left side if hjust = 0.)

y

The y location of the plot. (Bottom side if vjust = 0.)

width

Width of the plot.

height

Height of the plot.

scale

Scales the grob relative to the rectangle defined by x, y, width, height. A setting -of scale = 1 indicates no scaling.

hjust, vjust

Horizontal and vertical justification relative to x.

halign, valign

Horizontal and vertical justification of the plot inside -the box.

- - -

Examples

-
library(ggplot2) - -# make a plot -p <- ggplot(data.frame(x = 1:3, y = 1:3), aes(x, y)) + - geom_point() -# draw into the top-right corner of a larger plot area -ggdraw() + draw_plot(p, .6, .6, .4, .4) -
+
+
draw_plot(
+  plot,
+  x = 0,
+  y = 0,
+  width = 1,
+  height = 1,
+  scale = 1,
+  hjust = 0,
+  vjust = 0,
+  halign = 0.5,
+  valign = 0.5
+)
+
+ +
+

Arguments

+
plot
+

The plot to place. Can be a ggplot2 plot, an arbitrary grob or gtable, +or a recorded base-R plot, as in as_grob().

+ + +
x
+

The x location of the plot. (Left side if hjust = 0.)

+ + +
y
+

The y location of the plot. (Bottom side if vjust = 0.)

+ + +
width
+

Width of the plot.

+ + +
height
+

Height of the plot.

+ + +
scale
+

Scales the grob relative to the rectangle defined by x, y, width, height. A setting +of scale = 1 indicates no scaling.

+ + +
hjust, vjust
+

Horizontal and vertical justification relative to x.

+ + +
halign, valign
+

Horizontal and vertical justification of the plot inside +the box.

+ +
+ +
+

Examples

+
library(ggplot2)
+
+# make a plot
+p <- ggplot(data.frame(x = 1:3, y = 1:3), aes(x, y)) +
+    geom_point()
+# draw into the top-right corner of a larger plot area
+ggdraw() + draw_plot(p, .6, .6, .4, .4)
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/draw_plot_label.html b/docs/reference/draw_plot_label.html index fc7f780..c1619cd 100644 --- a/docs/reference/draw_plot_label.html +++ b/docs/reference/draw_plot_label.html @@ -1,77 +1,14 @@ - - - - - - - -Add a label to a plot — draw_plot_label • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Add a label to a plot — draw_plot_label • cowplot - - - - - - - - - - - + + - - - -
-
- -
- -
+

This function adds a plot label to the upper left corner of a graph (or an arbitrarily specified position). It takes all the same parameters -as draw_text, but has defaults that make it convenient to label graphs with letters A, B, C, etc. Just like draw_text(), +as draw_text, but has defaults that make it convenient to label graphs with letters A, B, C, etc. Just like draw_text(), it can handle vectors of labels with associated coordinates.

-
draw_plot_label(
-  label,
-  x = 0,
-  y = 1,
-  hjust = -0.5,
-  vjust = 1.5,
-  size = 16,
-  fontface = "bold",
-  family = NULL,
-  color = NULL,
-  colour,
-  ...
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
label

String (or vector of strings) to be drawn as the label.

x

The x position (or vector thereof) of the label(s).

y

The y position (or vector thereof) of the label(s).

hjust

Horizontal adjustment.

vjust

Vertical adjustment.

size

Font size of the label to be drawn.

fontface

Font face of the label to be drawn.

family

(optional) Font family of the plot labels. If not provided, is taken from the current theme.

color, colour

(optional) Color of the plot labels. If not provided, is taken from the current theme.

...

Other arguments to be handed to draw_text.

+
+
draw_plot_label(
+  label,
+  x = 0,
+  y = 1,
+  hjust = -0.5,
+  vjust = 1.5,
+  size = 16,
+  fontface = "bold",
+  family = NULL,
+  color = NULL,
+  colour,
+  ...
+)
+
+ +
+

Arguments

+
label
+

String (or vector of strings) to be drawn as the label.

+ + +
x
+

The x position (or vector thereof) of the label(s).

+ + +
y
+

The y position (or vector thereof) of the label(s).

+ + +
hjust
+

Horizontal adjustment.

+ +
vjust
+

Vertical adjustment.

+ + +
size
+

Font size of the label to be drawn.

+ + +
fontface
+

Font face of the label to be drawn.

+ + +
family
+

(optional) Font family of the plot labels. If not provided, is taken from the current theme.

+ + +
color, colour
+

(optional) Color of the plot labels. If not provided, is taken from the current theme.

+ + +
...
+

Other arguments to be handed to draw_text.

+ +
+
-
- +
- - + + diff --git a/docs/reference/draw_text-1.png b/docs/reference/draw_text-1.png index e08face..464da0d 100644 Binary files a/docs/reference/draw_text-1.png and b/docs/reference/draw_text-1.png differ diff --git a/docs/reference/draw_text-2.png b/docs/reference/draw_text-2.png index 403041f..718652c 100644 Binary files a/docs/reference/draw_text-2.png and b/docs/reference/draw_text-2.png differ diff --git a/docs/reference/draw_text.html b/docs/reference/draw_text.html index 7a543af..67c7415 100644 --- a/docs/reference/draw_text.html +++ b/docs/reference/draw_text.html @@ -1,76 +1,13 @@ - - - - - - - -Draw multiple text-strings in one go. — draw_text • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Draw multiple text-strings in one go. — draw_text • cowplot + + - - - - -
-
- -
- -
+
@@ -160,89 +82,91 @@

Draw multiple text-strings in one go.

handle mathematical expressions, though. For those, use draw_label.

-
draw_text(text, x = 0.5, y = 0.5, size = 14, hjust = 0.5, vjust = 0.5, ...)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
text

A vector of Character (not expressions) specifying the string(s) to be written.

x

Vector of x coordinates.

y

Vector of y coordinates.

size

Font size of the text to be drawn.

hjust

(default = 0.5)

vjust

(default = 0.5)

...

Style parameters, such as colour, alpha, angle, size, etc.

- -

Details

+
+
draw_text(text, x = 0.5, y = 0.5, size = 14, hjust = 0.5, vjust = 0.5, ...)
+
+ +
+

Arguments

+
text
+

A vector of Character (not expressions) specifying the string(s) to be written.

+ + +
x
+

Vector of x coordinates.

+ + +
y
+

Vector of y coordinates.

+ + +
size
+

Font size of the text to be drawn.

+ +
hjust
+

(default = 0.5)

+ + +
vjust
+

(default = 0.5)

+ + +
...
+

Style parameters, such as colour, alpha, angle, size, etc.

+ +
+
+

Details

Note that font sizes are scaled by a factor of 2.85, so sizes agree with those of the theme. This is different from geom_text in ggplot2.

By default, the x and y coordinates specify the center of the text box. Set hjust = 0, vjust = 0 to specify the lower left corner, and other values of hjust and vjust for any other relative location you want to specify.

-

For a full list of ... options, see geom_label.

-

See also

- - - -

Examples

-
# Draw onto a 1*1 drawing surface -ggdraw() + draw_text("Hello World!", x = 0.5, y = 0.5) -
# -# Adorn a plot from the Anscombe data set of "identical" data. -library(ggplot2) - -p <- ggplot(anscombe, aes(x1, y1)) + geom_point() + geom_smooth() -three_strings <- c("Hello World!", "to be or not to be", "over and out") -p + draw_text(three_strings, x = 8:10, y = 5:7, hjust = 0) -
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'
+

For a full list of ... options, see geom_label.

+
+
+

See also

+ +
+ +
+

Examples

+
# Draw onto a 1*1 drawing surface
+ggdraw() + draw_text("Hello World!", x = 0.5, y = 0.5)
+
+#
+# Adorn a plot from the Anscombe data set of "identical" data.
+library(ggplot2)
+
+p <- ggplot(anscombe, aes(x1, y1)) + geom_point() + geom_smooth()
+three_strings <- c("Hello World!", "to be or not to be", "over and out")
+p + draw_text(three_strings, x = 8:10, y = 5:7, hjust = 0)
+#> `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/get_legend-1.png b/docs/reference/get_legend-1.png index 35ff3e1..0a84c35 100644 Binary files a/docs/reference/get_legend-1.png and b/docs/reference/get_legend-1.png differ diff --git a/docs/reference/get_legend-2.png b/docs/reference/get_legend-2.png index f5242ac..4350b62 100644 Binary files a/docs/reference/get_legend-2.png and b/docs/reference/get_legend-2.png differ diff --git a/docs/reference/get_legend.html b/docs/reference/get_legend.html index dc14e85..c88eb13 100644 --- a/docs/reference/get_legend.html +++ b/docs/reference/get_legend.html @@ -1,75 +1,12 @@ - - - - - - - -Retrieve the legend of a plot — get_legend • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Retrieve the legend of a plot — get_legend • cowplot - + + - - - -
-
- -
- -
+
@@ -158,62 +80,65 @@

Retrieve the legend of a plot

This function extracts just the legend from a ggplot

-
get_legend(plot)
- -

Arguments

- - - - - - -
plot

A ggplot or gtable from which to retrieve the legend

- -

Value

- -

A gtable object holding just the legend or NULL if there is no legend.

- -

Examples

-
library(ggplot2) -theme_set(theme_half_open()) - -p1 <- ggplot(mtcars, aes(mpg, disp)) + geom_line() -plot.mpg <- ggplot(mpg, aes(x = cty, y = hwy, colour = factor(cyl))) + geom_point(size=2.5) -# Note that these cannot be aligned vertically due to the legend in the plot.mpg -ggdraw(plot_grid(p1, plot.mpg, ncol=1, align='v')) -
#> Warning: Graphs cannot be vertically aligned unless the axis parameter is set. Placing graphs unaligned.
-legend <- get_legend(plot.mpg) -plot.mpg <- plot.mpg + theme(legend.position='none') -# Now plots are aligned vertically with the legend to the right -ggdraw(plot_grid(plot_grid(p1, plot.mpg, ncol=1, align='v'), - plot_grid(NULL, legend, ncol=1), - rel_widths=c(1, 0.2))) -
+
+
get_legend(plot)
+
+ +
+

Arguments

+
plot
+

A ggplot or gtable from which to retrieve the legend

+ +
+
+

Value

+ + +

A gtable object holding just the legend or NULL if there is no legend.

+
+ +
+

Examples

+
library(ggplot2)
+theme_set(theme_half_open())
+
+p1 <- ggplot(mtcars, aes(mpg, disp)) + geom_line()
+plot.mpg <- ggplot(mpg, aes(x = cty, y = hwy, colour = factor(cyl))) + geom_point(size=2.5)
+# Note that these cannot be aligned vertically due to the legend in the plot.mpg
+ggdraw(plot_grid(p1, plot.mpg, ncol=1, align='v'))
+#> Warning: Graphs cannot be vertically aligned unless the axis parameter is set. Placing graphs unaligned.
+
+
+legend <- get_legend(plot.mpg)
+plot.mpg <- plot.mpg + theme(legend.position='none')
+# Now plots are aligned vertically with the legend to the right
+ggdraw(plot_grid(plot_grid(p1, plot.mpg, ncol=1, align='v'),
+                 plot_grid(NULL, legend, ncol=1),
+                 rel_widths=c(1, 0.2)))
+
+
+
+
-
- +

- - + + diff --git a/docs/reference/get_panel-1.png b/docs/reference/get_panel-1.png index 507815d..e907e96 100644 Binary files a/docs/reference/get_panel-1.png and b/docs/reference/get_panel-1.png differ diff --git a/docs/reference/get_panel-2.png b/docs/reference/get_panel-2.png index 507815d..e907e96 100644 Binary files a/docs/reference/get_panel-2.png and b/docs/reference/get_panel-2.png differ diff --git a/docs/reference/get_panel.html b/docs/reference/get_panel.html index dff88cb..e020b3e 100644 --- a/docs/reference/get_panel.html +++ b/docs/reference/get_panel.html @@ -1,77 +1,14 @@ - - - - - - - -Retrieve the panel or part of a panel of a plot — get_panel • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Retrieve the panel or part of a panel of a plot — get_panel • cowplot - - - - - - - - - - - - + + - - -
-
- -
- -
+
@@ -162,72 +84,74 @@

Retrieve the panel or part of a panel of a plot

panel, such as geoms.

-
get_panel(plot, panel = NULL, return_all = FALSE)
-
-get_panel_component(panel, pattern)
- -

Arguments

- - - - - - - - - - - - - - - - - - -
plot

A ggplot or gtable from which to retrieve the panel

panel

An integer indicating which panel to pull. ggplot orders panels -column-wise, so this is in order from the top left down.

return_all

If there is more than one panel, should all be returned -as a list? Default is FALSE.

pattern

the name of the component

- -

Value

- -

A gtable object holding the panel(s) or a grob of the component

- -

Examples

-
library(ggplot2) - -p <- ggplot(mpg, aes(displ, cty)) + geom_point() -plot_panel <- get_panel(p) -ggdraw(plot_panel) -
-ggdraw(get_panel_component(plot_panel, "geom_point")) -
-
+
+
get_panel(plot, panel = NULL, return_all = FALSE)
+
+get_panel_component(panel, pattern)
+
+ +
+

Arguments

+
plot
+

A ggplot or gtable from which to retrieve the panel

+ + +
panel
+

An integer indicating which panel to pull. ggplot orders panels +column-wise, so this is in order from the top left down.

+ + +
return_all
+

If there is more than one panel, should all be returned +as a list? Default is FALSE.

+ + +
pattern
+

the name of the component

+ +
+
+

Value

+ + +

A gtable object holding the panel(s) or a grob of the component

+
+ +
+

Examples

+
library(ggplot2)
+
+p <- ggplot(mpg, aes(displ, cty)) + geom_point()
+plot_panel <- get_panel(p)
+ggdraw(plot_panel)
+
+
+ggdraw(get_panel_component(plot_panel, "geom_point"))
+
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/get_plot_component-1.png b/docs/reference/get_plot_component-1.png index f75832d..071b130 100644 Binary files a/docs/reference/get_plot_component-1.png and b/docs/reference/get_plot_component-1.png differ diff --git a/docs/reference/get_plot_component.html b/docs/reference/get_plot_component.html index 4242370..d530110 100644 --- a/docs/reference/get_plot_component.html +++ b/docs/reference/get_plot_component.html @@ -1,78 +1,15 @@ - - - - - - - -Get plot components — get_plot_component • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Get plot components — get_plot_component • cowplot - - - - - - - - - - - - - - + + -
-
- -
- -
+
@@ -164,67 +86,68 @@

Get plot components

components as a list.

-
get_plot_component(plot, pattern, return_all = FALSE)
-
-plot_component_names(plot)
-
-plot_components(plot)
- -

Arguments

- - - - - - - - - - - - - - -
plot

A ggplot or gtable to extract from.

pattern

The name of the component.

return_all

If there is more than one component, should all be returned -as a list? Default is FALSE.

- -

Value

- -

A grob or list of grobs (get_plot_component(), plot_components()) -or a character vector (plot_component_names())

+
+
get_plot_component(plot, pattern, return_all = FALSE)
+
+plot_component_names(plot)
+
+plot_components(plot)
+
+ +
+

Arguments

+
plot
+

A ggplot or gtable to extract from.

-

Examples

-
library(ggplot2) -p <- ggplot(mpg, aes(displ, cty)) + geom_point() -ggdraw(get_plot_component(p, "ylab-l")) -
-
+
pattern
+

The name of the component.

+ + +
return_all
+

If there is more than one component, should all be returned +as a list? Default is FALSE.

+ +
+
+

Value

+ + +

A grob or list of grobs (get_plot_component(), plot_components()) +or a character vector (plot_component_names())

+
+ +
+

Examples

+
library(ggplot2)
+
+p <- ggplot(mpg, aes(displ, cty)) + geom_point()
+ggdraw(get_plot_component(p, "ylab-l"))
+
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/get_title-1.png b/docs/reference/get_title-1.png index 7947f61..f52105e 100644 Binary files a/docs/reference/get_title-1.png and b/docs/reference/get_title-1.png differ diff --git a/docs/reference/get_title-2.png b/docs/reference/get_title-2.png index 39a2881..1cb4a3b 100644 Binary files a/docs/reference/get_title-2.png and b/docs/reference/get_title-2.png differ diff --git a/docs/reference/get_title.html b/docs/reference/get_title.html index f2de542..6ccd21a 100644 --- a/docs/reference/get_title.html +++ b/docs/reference/get_title.html @@ -1,76 +1,13 @@ - - - - - - - -Get plot titles — get_title • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Get plot titles — get_title • cowplot - - + + - - -
-
- -
- -
+
@@ -160,58 +82,57 @@

Get plot titles

the title, while get_subtitle() pulls the subtitle.

-
get_title(plot)
-
-get_subtitle(plot)
- -

Arguments

- - - - - - -
plot

A ggplot or gtable.

- - -

Examples

-
library(ggplot2) - -p <- ggplot(mpg, aes(displ, cty)) + - geom_point() + - labs( - title = "Plot title", - subtitle = "Plot subtitle" - ) -ggdraw(get_title(p)) -
ggdraw(get_subtitle(p)) -
-
+
+
get_title(plot)
+
+get_subtitle(plot)
+
+ +
+

Arguments

+
plot
+

A ggplot or gtable.

+ +
+ +
+

Examples

+
library(ggplot2)
+
+p <- ggplot(mpg, aes(displ, cty)) +
+  geom_point() +
+  labs(
+    title = "Plot title",
+    subtitle = "Plot subtitle"
+  )
+ggdraw(get_title(p))
+
+ggdraw(get_subtitle(p))
+
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/get_y_axis-1.png b/docs/reference/get_y_axis-1.png index 2a8b044..11d8915 100644 Binary files a/docs/reference/get_y_axis-1.png and b/docs/reference/get_y_axis-1.png differ diff --git a/docs/reference/get_y_axis-2.png b/docs/reference/get_y_axis-2.png index 57569cb..c10cc03 100644 Binary files a/docs/reference/get_y_axis-2.png and b/docs/reference/get_y_axis-2.png differ diff --git a/docs/reference/get_y_axis.html b/docs/reference/get_y_axis.html index bca8847..cd9f271 100644 --- a/docs/reference/get_y_axis.html +++ b/docs/reference/get_y_axis.html @@ -1,76 +1,13 @@ - - - - - - - -Get plot axes — get_y_axis • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Get plot axes — get_y_axis • cowplot - + + - - - -
-
- -
- -
+
@@ -160,61 +82,60 @@

Get plot axes

the y-axis, while get_x_axis() pulls the x-axis.

-
get_y_axis(plot, position = c("left", "right"))
-
-get_x_axis(plot, position = c("bottom", "top"))
- -

Arguments

- - - - - - - - - - -
plot

A ggplot or gtable.

position

Which side of the plot is the axis on? For the x-axis, this -can be "top" or "bottom", and for the y-axis, it can be "left" or "right".

- - -

Examples

-
library(ggplot2) - -p <- ggplot(mpg, aes(displ, cty)) + - geom_point() +
+
get_y_axis(plot, position = c("left", "right"))
+
+get_x_axis(plot, position = c("bottom", "top"))
+
-ggdraw(get_y_axis(p)) -
p <- p + scale_x_continuous(position = "top") -ggdraw(get_x_axis(p, position = "top")) -
-
+
+

Arguments

+
plot
+

A ggplot or gtable.

+ + +
position
+

Which side of the plot is the axis on? For the x-axis, this +can be "top" or "bottom", and for the y-axis, it can be "left" or "right".

+ +
+ +
+

Examples

+
library(ggplot2)
+
+p <- ggplot(mpg, aes(displ, cty)) +
+  geom_point()
+
+ggdraw(get_y_axis(p))
+
+p <- p + scale_x_continuous(position = "top")
+ggdraw(get_x_axis(p, position = "top"))
+
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/ggdraw-1.png b/docs/reference/ggdraw-1.png index 5d8cf34..4c14c1c 100644 Binary files a/docs/reference/ggdraw-1.png and b/docs/reference/ggdraw-1.png differ diff --git a/docs/reference/ggdraw.html b/docs/reference/ggdraw.html index a521325..a10cc94 100644 --- a/docs/reference/ggdraw.html +++ b/docs/reference/ggdraw.html @@ -1,75 +1,12 @@ - - - - - - - -Set up a drawing layer on top of a ggplot — ggdraw • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Set up a drawing layer on top of a ggplot — ggdraw • cowplot - - - - + + -
-
- -
- -
+
@@ -158,64 +80,62 @@

Set up a drawing layer on top of a ggplot

Set up a drawing layer on top of a ggplot.

-
ggdraw(plot = NULL, xlim = c(0, 1), ylim = c(0, 1), clip = "off")
- -

Arguments

- - - - - - - - - - - - - - - - - - -
plot

The plot to use as a starting point. Can be a ggplot2 plot, an arbitrary -grob or gtable, or a recorded base-R plot, as in as_grob().

xlim

The x-axis limits for the drawing layer.

ylim

The y-axis limits for the drawing layer.

clip

Should drawing be clipped to the set limits? The default is no ("off").

- - -

Examples

-
library(ggplot2) - -p <- ggplot(mpg, aes(displ, cty)) + - geom_point() + - theme_minimal_grid() -ggdraw(p) + draw_label("Draft", colour = "#80404080", size = 120, angle = 45) -
+
+
ggdraw(plot = NULL, xlim = c(0, 1), ylim = c(0, 1), clip = "off")
+
+ +
+

Arguments

+
plot
+

The plot to use as a starting point. Can be a ggplot2 plot, an arbitrary +grob or gtable, or a recorded base-R plot, as in as_grob().

+ + +
xlim
+

The x-axis limits for the drawing layer.

+ + +
ylim
+

The y-axis limits for the drawing layer.

+ + +
clip
+

Should drawing be clipped to the set limits? The default is no ("off").

+ +
+ +
+

Examples

+
library(ggplot2)
+
+p <- ggplot(mpg, aes(displ, cty)) +
+  geom_point() +
+  theme_minimal_grid()
+ggdraw(p) + draw_label("Draft", colour = "#80404080", size = 120, angle = 45)
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/ggsave2.html b/docs/reference/ggsave2.html index 66b62a6..60df7ab 100644 --- a/docs/reference/ggsave2.html +++ b/docs/reference/ggsave2.html @@ -1,77 +1,14 @@ - - - - - - - -Cowplot reimplementation of ggsave(). — ggsave2 • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Cowplot reimplementation of ggsave(). — ggsave2 • cowplot - - - - - - - - - - - - + + - - -
-
- -
- -
+
-

This function behaves just like ggsave() from ggplot2. The main difference is +

This function behaves just like ggsave() from ggplot2. The main difference is that by default it doesn't use the Dingbats font for pdf output. The Dingbats font causes problems with some pdf readers.

-
ggsave2(
-  filename,
-  plot = ggplot2::last_plot(),
-  device = NULL,
-  path = NULL,
-  scale = 1,
-  width = NA,
-  height = NA,
-  units = c("in", "cm", "mm"),
-  dpi = 300,
-  limitsize = TRUE,
-  ...
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
filename

Filename of the plot.

plot

Plot to save, defaults to last plot displayed.

device

Device to use, automatically extract from file name extension.

path

Path to save plot to (if you just want to set path and not -filename).

scale

Scaling factor.

width

Width (defaults to the width of current plotting window).

height

Height (defaults to the height of current plotting window).

units

Units for width and height when either one is explicitly specified (in, cm, or mm).

dpi

DPI to use for raster graphics.

limitsize

When TRUE (the default), ggsave2() will not +

+
ggsave2(
+  filename,
+  plot = ggplot2::last_plot(),
+  device = NULL,
+  path = NULL,
+  scale = 1,
+  width = NA,
+  height = NA,
+  units = c("in", "cm", "mm"),
+  dpi = 300,
+  limitsize = TRUE,
+  ...
+)
+
+ +
+

Arguments

+
filename
+

Filename of the plot.

+ + +
plot
+

Plot to save, defaults to last plot displayed.

+ + +
device
+

Device to use, automatically extract from file name extension.

+ + +
path
+

Path to save plot to (if you just want to set path and not +filename).

+ + +
scale
+

Scaling factor.

+ + +
width
+

Width (defaults to the width of current plotting window).

+ + +
height
+

Height (defaults to the height of current plotting window).

+ + +
units
+

Units for width and height when either one is explicitly specified (in, cm, or mm).

+ + +
dpi
+

DPI to use for raster graphics.

+ + +
limitsize
+

When TRUE (the default), ggsave2() will not save images larger than 50x50 inches, to prevent the common error of -specifying dimensions in pixels.

...

Other arguments to be handed to the plot device.

+specifying dimensions in pixels.

+ +
...
+

Other arguments to be handed to the plot device.

+ +
+
-
- +
- - + + diff --git a/docs/reference/gtable_remove_grobs.html b/docs/reference/gtable_remove_grobs.html index 58c7adf..4cefa32 100644 --- a/docs/reference/gtable_remove_grobs.html +++ b/docs/reference/gtable_remove_grobs.html @@ -1,75 +1,12 @@ - - - - - - - -Remove named elements from gtable — gtable_remove_grobs • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Remove named elements from gtable — gtable_remove_grobs • cowplot + + - - - - -
-
- -
- -
+
@@ -158,52 +80,47 @@

Remove named elements from gtable

Remove named elements from gtable

-
gtable_remove_grobs(table, names, ...)
- -

Arguments

- - - - - - - - - - - - - - -
table

The table from which grobs should be removed

names

A character vector of the grob names (as listed in table$layout) -that should be removed

...

Other parameters passed through to gtable_filter.

+
+
gtable_remove_grobs(table, names, ...)
+
+ +
+

Arguments

+
table
+

The table from which grobs should be removed

+ + +
names
+

A character vector of the grob names (as listed in table$layout) +that should be removed

+
...
+

Other parameters passed through to gtable_filter.

+ +
+
+
-
- +
- - + + diff --git a/docs/reference/gtable_squash_cols.html b/docs/reference/gtable_squash_cols.html index 9a0a10b..b7d4878 100644 --- a/docs/reference/gtable_squash_cols.html +++ b/docs/reference/gtable_squash_cols.html @@ -1,75 +1,12 @@ - - - - - - - -Set the width of given columns to 0. — gtable_squash_cols • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Set the width of given columns to 0. — gtable_squash_cols • cowplot - - + + - - -
-
- -
- -
+
@@ -158,47 +80,42 @@

Set the width of given columns to 0.

Set the width of given columns to 0.

-
gtable_squash_cols(table, cols)
+
+
gtable_squash_cols(table, cols)
+
+ +
+

Arguments

+
table
+

The gtable on which to operate

+ -

Arguments

- - - - - - - - - - -
table

The gtable on which to operate

cols

Numerical vector indicating the columns whose width should be set to zero.

+
cols
+

Numerical vector indicating the columns whose width should be set to zero.

+
+
-
- +
- - + + diff --git a/docs/reference/gtable_squash_rows.html b/docs/reference/gtable_squash_rows.html index 9ca4c36..98a8bbc 100644 --- a/docs/reference/gtable_squash_rows.html +++ b/docs/reference/gtable_squash_rows.html @@ -1,75 +1,12 @@ - - - - - - - -Set the height of given rows to 0. — gtable_squash_rows • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Set the height of given rows to 0. — gtable_squash_rows • cowplot - - + + - - -
-
- -
- -
+
@@ -158,47 +80,42 @@

Set the height of given rows to 0.

Set the height of given rows to 0.

-
gtable_squash_rows(table, rows)
+
+
gtable_squash_rows(table, rows)
+
+ +
+

Arguments

+
table
+

The gtable on which to operate

+ -

Arguments

- - - - - - - - - - -
table

The gtable on which to operate

rows

Numerical vector indicating the rows whose heights should be set to zero.

+
rows
+

Numerical vector indicating the rows whose heights should be set to zero.

+
+
-
- +
- - + + diff --git a/docs/reference/index.html b/docs/reference/index.html index cff762f..6b546a3 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -1,74 +1,12 @@ - - - - - - - -Function reference • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Function reference • cowplot - - - - + + -
-
- -
- -
+
- - - - - - - - - - -
-

Plot composition

-

Arranging and aligning plots

+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+

Plot composition

+

Arranging and aligning plots

+

align_margin()

Align multiple plots along a specified margin

+

align_plots()

Align multiple plots vertically and/or horizontally

+

plot_grid()

Arrange multiple plots into a grid

-

Drawing

-

Place elements on the canvas

+
+

Drawing

+

Place elements on the canvas

+

draw_figure_label()

Add a label to a figure

+

draw_grob()

Draw a grob.

+

draw_image()

Draw an image

+

draw_label()

Draw a text label or mathematical expression.

+

draw_line()

Draw a line from connected points

+

draw_plot()

Draw a (sub)plot.

+

draw_plot_label()

Add a label to a plot

+

draw_text()

Draw multiple text-strings in one go.

+

stamp() stamp_good() stamp_bad() stamp_wrong() stamp_ugly()

Stamp plots with a label, such as good, bad, or ugly.

+

ggdraw()

Set up a drawing layer on top of a ggplot

+

add_sub()

Add annotation underneath a plot

+

axis_canvas()

Generates a canvas onto which one can draw axis-like objects.

-

Themes

-

Modify plot appearance

+
+

Themes

+

Modify plot appearance

+

theme_cowplot() theme_half_open()

Create the default cowplot theme

+

theme_map()

Create a theme for map plotting

+

theme_minimal_grid() theme_minimal_vgrid() theme_minimal_hgrid()

Minimalistic themes with grids

+

theme_nothing()

Create a completely empty theme

+

background_grid()

Add/modify/remove the background grid in a ggplot2 plot

+

panel_border()

Add/remove the panel border in a ggplot2 plot

+

rectangle_key_glyph() circle_key_glyph()

Create customizable legend key glyphs

-

Get methods

-

Retrieve elements of a plot

+
+

Get methods

+

Retrieve elements of a plot

+

get_legend()

Retrieve the legend of a plot

+

get_panel() get_panel_component()

Retrieve the panel or part of a panel of a plot

+

get_plot_component() plot_component_names() plot_components()

Get plot components

+

get_title() get_subtitle()

Get plot titles

+

get_y_axis() get_x_axis()

Get plot axes

-

Grobs

-

Manipulate and convert grobs

+
+

Grobs

+

Manipulate and convert grobs

+

gtable_remove_grobs()

Remove named elements from gtable

+

gtable_squash_cols()

Set the width of given columns to 0.

+

gtable_squash_rows()

Set the height of given rows to 0.

+

as_grob()

Convert a base plot or a ggplot2 plot into a grob

+

as_gtable() plot_to_gtable()

Convert plot or other graphics object into a gtable

+

insert_xaxis_grob() insert_yaxis_grob()

Insert an axis-like grob on either side of a plot panel in a ggplot2 plot.

-

Output

-

Render figures to an output

+
+

Output

+

Render figures to an output

+

ggsave2()

Cowplot reimplementation of ggsave().

+

save_plot()

Alternative to ggsave(), with better support for multi-figure plots.

+

png_null_device() pdf_null_device() cairo_null_device() agg_null_device()

Null devices

+

set_null_device()

Sets the null graphics device

- +
+
-
- +
- - + + diff --git a/docs/reference/insert_xaxis_grob.html b/docs/reference/insert_xaxis_grob.html index f59014a..0f26d1e 100644 --- a/docs/reference/insert_xaxis_grob.html +++ b/docs/reference/insert_xaxis_grob.html @@ -1,75 +1,12 @@ - - - - - - - -Insert an axis-like grob on either side of a plot panel in a ggplot2 plot. — insert_xaxis_grob • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Insert an axis-like grob on either side of a plot panel in a ggplot2 plot. — insert_xaxis_grob • cowplot - - + + - - -
-
- -
- -
+
-

The function insert_xaxis_grob() inserts a grob at the top or bottom of the plot panel in a ggplot2 plot.

+

The function insert_xaxis_grob() inserts a grob at the top or bottom of the plot panel in a ggplot2 plot.

+
+ +
+
insert_xaxis_grob(
+  plot,
+  grob,
+  height = grid::unit(0.2, "null"),
+  position = c("top", "bottom"),
+  clip = "on"
+)
+
+insert_yaxis_grob(
+  plot,
+  grob,
+  width = grid::unit(0.2, "null"),
+  position = c("right", "left"),
+  clip = "on"
+)
-
insert_xaxis_grob(
-  plot,
-  grob,
-  height = grid::unit(0.2, "null"),
-  position = c("top", "bottom"),
-  clip = "on"
-)
-
-insert_yaxis_grob(
-  plot,
-  grob,
-  width = grid::unit(0.2, "null"),
-  position = c("right", "left"),
-  clip = "on"
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - -
plot

The plot into which the grob will be inserted.

grob

The grob to insert. This will generally have been obtained via get_panel() -from a ggplot2 object, in particular one generated with axis_canvas(). If a ggplot2 -plot is provided instead of a grob, then get_panel() is called to extract the -panel grob.

height

The height of the grob, in grid units. Used by insert_xaxis_grob().

position

The position of the grob. Can be "right" or "left" for insert_yaxis_grob() -and "top" or "botton" for insert_xaxis_grob().

clip

Set to "off" to turn off clipping of the inserted grob.

width

The width of the grob, in grid units. Used by insert_yaxis_grob().

- -

Details

- -

For usage examples, see axis_canvas().

+
+

Arguments

+
plot
+

The plot into which the grob will be inserted.

+ + +
grob
+

The grob to insert. This will generally have been obtained via get_panel() +from a ggplot2 object, in particular one generated with axis_canvas(). If a ggplot2 +plot is provided instead of a grob, then get_panel() is called to extract the +panel grob.

+ + +
height
+

The height of the grob, in grid units. Used by insert_xaxis_grob().

+ + +
position
+

The position of the grob. Can be "right" or "left" for insert_yaxis_grob() +and "top" or "botton" for insert_xaxis_grob().

+ + +
clip
+

Set to "off" to turn off clipping of the inserted grob.

+ + +
width
+

The width of the grob, in grid units. Used by insert_yaxis_grob().

+ +
+
+

Details

+

For usage examples, see axis_canvas().

+
+
-
- +
- - + + diff --git a/docs/reference/panel_border.html b/docs/reference/panel_border.html index 5580db3..7e5f288 100644 --- a/docs/reference/panel_border.html +++ b/docs/reference/panel_border.html @@ -1,77 +1,14 @@ - - - - - - - -Add/remove the panel border in a ggplot2 plot — panel_border • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Add/remove the panel border in a ggplot2 plot — panel_border • cowplot - - - - - - - - - - - + + - - - -
-
- -
- -
+

This function provides a simple way to modify the panel border in ggplot2. It -doesn't do anything that can't be done just the same with theme(). However, it +doesn't do anything that can't be done just the same with theme(). However, it saves some typing.

-
panel_border(color = "grey85", size = 1, linetype = 1, remove = FALSE, colour)
- -

Arguments

- - - - - - - - - - - - - - - - - - -
color, colour

The color of the border.

size

Size. Needs to be twice as large as desired outcome when panel clipping -is on (the default).

linetype

Line type.

remove

If TRUE, removes the current panel border.

+
+
panel_border(color = "grey85", size = 1, linetype = 1, remove = FALSE, colour)
+
+ +
+

Arguments

+
color, colour
+

The color of the border.

+ + +
size
+

Size. Needs to be twice as large as desired outcome when panel clipping +is on (the default).

+ +
linetype
+

Line type.

+ + +
remove
+

If TRUE, removes the current panel border.

+ +
+
-
- +
- - + + diff --git a/docs/reference/plot_grid-1.png b/docs/reference/plot_grid-1.png index bdce8ff..5fe301a 100644 Binary files a/docs/reference/plot_grid-1.png and b/docs/reference/plot_grid-1.png differ diff --git a/docs/reference/plot_grid-2.png b/docs/reference/plot_grid-2.png index 7f9ad0c..9c2cc59 100644 Binary files a/docs/reference/plot_grid-2.png and b/docs/reference/plot_grid-2.png differ diff --git a/docs/reference/plot_grid-3.png b/docs/reference/plot_grid-3.png index 9dc5814..4ffbbbb 100644 Binary files a/docs/reference/plot_grid-3.png and b/docs/reference/plot_grid-3.png differ diff --git a/docs/reference/plot_grid-4.png b/docs/reference/plot_grid-4.png index 02c2ade..1143049 100644 Binary files a/docs/reference/plot_grid-4.png and b/docs/reference/plot_grid-4.png differ diff --git a/docs/reference/plot_grid-5.png b/docs/reference/plot_grid-5.png index 5d628ff..6b1172f 100644 Binary files a/docs/reference/plot_grid-5.png and b/docs/reference/plot_grid-5.png differ diff --git a/docs/reference/plot_grid-6.png b/docs/reference/plot_grid-6.png index 44acbd7..056fd4d 100644 Binary files a/docs/reference/plot_grid-6.png and b/docs/reference/plot_grid-6.png differ diff --git a/docs/reference/plot_grid-7.png b/docs/reference/plot_grid-7.png index 0812efa..3834bf2 100644 Binary files a/docs/reference/plot_grid-7.png and b/docs/reference/plot_grid-7.png differ diff --git a/docs/reference/plot_grid-8.png b/docs/reference/plot_grid-8.png index 221227c..862f779 100644 Binary files a/docs/reference/plot_grid-8.png and b/docs/reference/plot_grid-8.png differ diff --git a/docs/reference/plot_grid-9.png b/docs/reference/plot_grid-9.png index 734cbc2..7ec9d7d 100644 Binary files a/docs/reference/plot_grid-9.png and b/docs/reference/plot_grid-9.png differ diff --git a/docs/reference/plot_grid.html b/docs/reference/plot_grid.html index 92ee1dc..7483c45 100644 --- a/docs/reference/plot_grid.html +++ b/docs/reference/plot_grid.html @@ -1,75 +1,12 @@ - - - - - - - -Arrange multiple plots into a grid — plot_grid • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Arrange multiple plots into a grid — plot_grid • cowplot - - + + - - -
-
- -
- -
+
@@ -158,259 +80,265 @@

Arrange multiple plots into a grid

Arrange multiple plots into a grid.

-
plot_grid(
-  ...,
-  plotlist = NULL,
-  align = c("none", "h", "v", "hv"),
-  axis = c("none", "l", "r", "t", "b", "lr", "tb", "tblr"),
-  nrow = NULL,
-  ncol = NULL,
-  rel_widths = 1,
-  rel_heights = 1,
-  labels = NULL,
-  label_size = 14,
-  label_fontfamily = NULL,
-  label_fontface = "bold",
-  label_colour = NULL,
-  label_x = 0,
-  label_y = 1,
-  hjust = -0.5,
-  vjust = 1.5,
-  scale = 1,
-  greedy = TRUE,
-  byrow = TRUE,
-  cols = NULL,
-  rows = NULL
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
...

List of plots to be arranged into the grid. The plots can be any objects that -the function as_gtable() can handle (see also examples).

plotlist

(optional) List of plots to display. Alternatively, the plots can be provided -individually as the first n arguments of the function plot_grid (see examples).

align

(optional) Specifies whether graphs in the grid should be horizontally ("h") or -vertically ("v") aligned. Options are "none" (default), "hv" (align in both directions), "h", and "v".

axis

(optional) Specifies whether graphs should be aligned by the left ("l"), right ("r"), top ("t"), or bottom ("b") +

+
plot_grid(
+  ...,
+  plotlist = NULL,
+  align = c("none", "h", "v", "hv"),
+  axis = c("none", "l", "r", "t", "b", "lr", "tb", "tblr"),
+  nrow = NULL,
+  ncol = NULL,
+  rel_widths = 1,
+  rel_heights = 1,
+  labels = NULL,
+  label_size = 14,
+  label_fontfamily = NULL,
+  label_fontface = "bold",
+  label_colour = NULL,
+  label_x = 0,
+  label_y = 1,
+  hjust = -0.5,
+  vjust = 1.5,
+  scale = 1,
+  greedy = TRUE,
+  byrow = TRUE,
+  cols = NULL,
+  rows = NULL
+)
+
+ +
+

Arguments

+
...
+

List of plots to be arranged into the grid. The plots can be any objects that +the function as_gtable() can handle (see also examples).

+ + +
plotlist
+

(optional) List of plots to display. Alternatively, the plots can be provided +individually as the first n arguments of the function plot_grid (see examples).

+ + +
align
+

(optional) Specifies whether graphs in the grid should be horizontally ("h") or +vertically ("v") aligned. Options are "none" (default), "hv" (align in both directions), "h", and "v".

+ + +
axis
+

(optional) Specifies whether graphs should be aligned by the left ("l"), right ("r"), top ("t"), or bottom ("b") margins. Options are "none" (default), or a string of any combination of l, r, t, and b in any order (e.g. "tblr" or "rlbt" for aligning all margins). -Must be specified if any of the graphs are complex (e.g. faceted) and alignment is specified and desired. See align_plots() for details.

nrow

(optional) Number of rows in the plot grid.

ncol

(optional) Number of columns in the plot grid.

rel_widths

(optional) Numerical vector of relative columns widths. For example, in a two-column +Must be specified if any of the graphs are complex (e.g. faceted) and alignment is specified and desired. See align_plots() for details.

+ + +
nrow
+

(optional) Number of rows in the plot grid.

+ + +
ncol
+

(optional) Number of columns in the plot grid.

+ + +
rel_widths
+

(optional) Numerical vector of relative columns widths. For example, in a two-column grid, rel_widths = c(2, 1) would make the first column twice as wide as the -second column.

rel_heights

(optional) Numerical vector of relative rows heights. Works just as -rel_widths does, but for rows rather than columns.

labels

(optional) List of labels to be added to the plots. You can also set labels="AUTO" to -auto-generate upper-case labels or labels="auto" to auto-generate lower-case labels.

label_size

(optional) Numerical value indicating the label size. Default is 14.

label_fontfamily

(optional) Font family of the plot labels. If not provided, is taken from the current theme.

label_fontface

(optional) Font face of the plot labels. Default is "bold".

label_colour

(optional) Color of the plot labels. If not provided, is taken from the current theme.

label_x

(optional) Single value or vector of x positions for plot labels, relative to each subplot. -Defaults to 0 for all labels. (Each label is placed all the way to the left of each plot.)

label_y

(optional) Single value or vector of y positions for plot labels, relative to each subplot. -Defaults to 1 for all labels. (Each label is placed all the way to the top of each plot.)

hjust

Adjusts the horizontal position of each label. More negative values move the label further +second column.

+ + +
rel_heights
+

(optional) Numerical vector of relative rows heights. Works just as +rel_widths does, but for rows rather than columns.

+ + +
labels
+

(optional) List of labels to be added to the plots. You can also set labels="AUTO" to +auto-generate upper-case labels or labels="auto" to auto-generate lower-case labels.

+ + +
label_size
+

(optional) Numerical value indicating the label size. Default is 14.

+ + +
label_fontfamily
+

(optional) Font family of the plot labels. If not provided, is taken from the current theme.

+ + +
label_fontface
+

(optional) Font face of the plot labels. Default is "bold".

+ + +
label_colour
+

(optional) Color of the plot labels. If not provided, is taken from the current theme.

+ + +
label_x
+

(optional) Single value or vector of x positions for plot labels, relative to each subplot. +Defaults to 0 for all labels. (Each label is placed all the way to the left of each plot.)

+ + +
label_y
+

(optional) Single value or vector of y positions for plot labels, relative to each subplot. +Defaults to 1 for all labels. (Each label is placed all the way to the top of each plot.)

+ + +
hjust
+

Adjusts the horizontal position of each label. More negative values move the label further to the right on the plot canvas. Can be a single value (applied to all labels) or a vector of values -(one for each label). Default is -0.5.

vjust

Adjusts the vertical position of each label. More positive values move the label further +(one for each label). Default is -0.5.

+ + +
vjust
+

Adjusts the vertical position of each label. More positive values move the label further down on the plot canvas. Can be a single value (applied to all labels) or a vector of values -(one for each label). Default is 1.5.

scale

Individual number or vector of numbers greater than 0. Enables you to scale the size of all or +(one for each label). Default is 1.5.

+ + +
scale
+

Individual number or vector of numbers greater than 0. Enables you to scale the size of all or select plots. Usually it's preferable to set margins instead of using scale, but scale can -sometimes be more powerful.

greedy

(optional) How should margins be adjusted during alignment. See align_plots() for details.

byrow

Logical value indicating if the plots should be arrange by row (default) or by column.

cols

Deprecated. Use ncol.

rows

Deprecated. Use nrow.

- - -

Examples

-
library(ggplot2) - -df <- data.frame( - x = 1:10, y1 = 1:10, y2 = (1:10)^2, y3 = (1:10)^3, y4 = (1:10)^4 -) - -p1 <- ggplot(df, aes(x, y1)) + geom_point() -p2 <- ggplot(df, aes(x, y2)) + geom_point() -p3 <- ggplot(df, aes(x, y3)) + geom_point() -p4 <- ggplot(df, aes(x, y4)) + geom_point() -p5 <- ggplot(mpg, aes(as.factor(year), hwy)) + - geom_boxplot() + - facet_wrap(~class, scales = "free_y") -# simple grid -plot_grid(p1, p2, p3, p4) -
-# simple grid with labels and aligned plots -plot_grid( - p1, p2, p3, p4, - labels = c('A', 'B', 'C', 'D'), - align="hv" -) -
-# manually setting the number of rows, auto-generate upper-case labels -plot_grid(p1, p2, p3, - nrow = 3, - labels = "AUTO", - label_size = 12, - align = "v" -) -
-# making rows and columns of different widths/heights -plot_grid( - p1, p2, p3, p4, - align = 'hv', - rel_heights = c(2,1), - rel_widths = c(1,2) -) -
-# aligning complex plots in a grid -plot_grid( - p1, p5, - align = "h", axis = "b", nrow = 1, rel_widths = c(1, 2) -) -
-# more examples -# \donttest{ -#' # missing plots in some grid locations, auto-generate lower-case labels -plot_grid( - p1, NULL, NULL, p2, p3, NULL, - ncol = 2, - labels = "auto", - label_size = 12, - align = "v" -) -
-# can arrange plots on the grid by column as well as by row. -plot_grid( - p1, NULL, p2, NULL, p3, - ncol = 2, - byrow = TRUE -) -
-# can align top of plotting area as well as bottom -plot_grid( - p1, p5, - align = "h", axis = "tb", - nrow = 1, rel_widths = c(1, 2) -) -
-# other types of plots not generated with ggplot -p6 <- ~{ - par( - mar = c(3, 3, 1, 1), - mgp = c(2, 1, 0) - ) - plot(sqrt) -} - -p7 <- function() { - par( - mar = c(2, 2, 1, 1), - mgp = c(2, 1, 0) - ) - image(volcano) -} -p8 <- grid::circleGrob() - -plot_grid(p1, p6, p7, p8, labels = "AUTO", scale = c(1, .9, .9, .7)) -
# } -
+sometimes be more powerful.

+ + +
greedy
+

(optional) How should margins be adjusted during alignment. See align_plots() for details.

+ + +
byrow
+

Logical value indicating if the plots should be arrange by row (default) or by column.

+ + +
cols
+

Deprecated. Use ncol.

+ + +
rows
+

Deprecated. Use nrow.

+ +
+ +
+

Examples

+
library(ggplot2)
+
+df <- data.frame(
+  x = 1:10, y1 = 1:10, y2 = (1:10)^2, y3 = (1:10)^3, y4 = (1:10)^4
+)
+
+p1 <- ggplot(df, aes(x, y1)) + geom_point()
+p2 <- ggplot(df, aes(x, y2)) + geom_point()
+p3 <- ggplot(df, aes(x, y3)) + geom_point()
+p4 <- ggplot(df, aes(x, y4)) + geom_point()
+p5 <- ggplot(mpg, aes(as.factor(year), hwy)) +
+        geom_boxplot() +
+        facet_wrap(~class, scales = "free_y")
+# simple grid
+plot_grid(p1, p2, p3, p4)
+
+
+# simple grid with labels and aligned plots
+plot_grid(
+  p1, p2, p3, p4,
+  labels = c('A', 'B', 'C', 'D'),
+  align="hv"
+)
+
+
+# manually setting the number of rows, auto-generate upper-case labels
+plot_grid(p1, p2, p3,
+  nrow = 3,
+  labels = "AUTO",
+  label_size = 12,
+  align = "v"
+)
+
+
+# making rows and columns of different widths/heights
+plot_grid(
+  p1, p2, p3, p4,
+  align = 'hv',
+  rel_heights = c(2,1),
+  rel_widths = c(1,2)
+)
+
+
+# aligning complex plots in a grid
+plot_grid(
+  p1, p5,
+  align = "h", axis = "b", nrow = 1, rel_widths = c(1, 2)
+)
+
+
+# more examples
+# \donttest{
+#' # missing plots in some grid locations, auto-generate lower-case labels
+plot_grid(
+  p1, NULL, NULL, p2, p3, NULL,
+  ncol = 2,
+  labels = "auto",
+  label_size = 12,
+  align = "v"
+)
+
+
+# can arrange plots on the grid by column as well as by row.
+plot_grid(
+  p1, NULL, p2, NULL, p3,
+  ncol = 2,
+  byrow = TRUE
+)
+
+
+# can align top of plotting area as well as bottom
+plot_grid(
+  p1, p5,
+  align = "h", axis = "tb",
+  nrow = 1, rel_widths = c(1, 2)
+)
+
+
+# other types of plots not generated with ggplot
+p6 <- ~{
+  par(
+    mar = c(3, 3, 1, 1),
+    mgp = c(2, 1, 0)
+  )
+  plot(sqrt)
+}
+
+p7 <- function() {
+  par(
+    mar = c(2, 2, 1, 1),
+    mgp = c(2, 1, 0)
+  )
+  image(volcano)
+}
+p8 <- grid::circleGrob()
+
+plot_grid(p1, p6, p7, p8, labels = "AUTO", scale = c(1, .9, .9, .7))
+
+# }
+
+
+

-
- +
- - + + diff --git a/docs/reference/png_null_device.html b/docs/reference/png_null_device.html index 054c86a..037cc8b 100644 --- a/docs/reference/png_null_device.html +++ b/docs/reference/png_null_device.html @@ -1,76 +1,13 @@ - - - - - - - -Null devices — png_null_device • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Null devices — png_null_device • cowplot - - - - + + -
-
- -
- -
+

Null devices to be used when rendering graphics in the background. See -set_null_device() for details.

+set_null_device() for details.

-
png_null_device(width, height)
-
-pdf_null_device(width, height)
+    
+
png_null_device(width, height)
+
+pdf_null_device(width, height)
+
+cairo_null_device(width, height)
+
+agg_null_device(width, height)
+
-cairo_null_device(width, height) +
+

Arguments

+
width
+

Device width in inch

-agg_null_device(width, height)
-

Arguments

- - - - - - - - - - -
width

Device width in inch

height

Device height in inch

+
height
+

Device height in inch

+
+
-
- +
- - + + diff --git a/docs/reference/rectangle_key_glyph-1.png b/docs/reference/rectangle_key_glyph-1.png index 19ad073..2d456e7 100644 Binary files a/docs/reference/rectangle_key_glyph-1.png and b/docs/reference/rectangle_key_glyph-1.png differ diff --git a/docs/reference/rectangle_key_glyph-2.png b/docs/reference/rectangle_key_glyph-2.png index 6ffadd0..7435f2a 100644 Binary files a/docs/reference/rectangle_key_glyph-2.png and b/docs/reference/rectangle_key_glyph-2.png differ diff --git a/docs/reference/rectangle_key_glyph.html b/docs/reference/rectangle_key_glyph.html index e82b1e0..e5bb658 100644 --- a/docs/reference/rectangle_key_glyph.html +++ b/docs/reference/rectangle_key_glyph.html @@ -1,76 +1,13 @@ - - - - - - - -Create customizable legend key glyphs — rectangle_key_glyph • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Create customizable legend key glyphs — rectangle_key_glyph • cowplot - + + - - - -
-
- -
- -
+
@@ -160,110 +82,109 @@

Create customizable legend key glyphs

circles.

-
rectangle_key_glyph(
-  colour = NA,
-  fill = fill,
-  alpha = alpha,
-  size = size,
-  linetype = linetype,
-  padding = unit(c(0, 0, 0, 0), "pt"),
-  color
-)
-
-circle_key_glyph(
-  colour = NA,
-  fill = fill,
-  alpha = alpha,
-  size = size,
-  linetype = linetype,
-  padding = unit(c(0, 0, 0, 0), "pt"),
-  color
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - -
colour, color

Unquoted name of the aesthetic to use for the outline color, -usually colour, color, or fill. Can also be a color constant, e.g. "red".

fill

Unquoted name of the aesthetic to use for the fill color, -usually colour, color, or fill. Can also be a color constant, e.g. "red".

alpha

Unquoted name of the aesthetic to use for alpha, -usually alpha. Can also be a numerical constant, e.g. 0.5.

size

Unquoted name of the aesthetic to use for the line thickness of the -outline, usually size. Can also be a numerical constant, e.g. 0.5.

linetype

Unquoted name of the aesthetic to use for the line type of the -outline, usually linetype. Can also be a constant, e.g. 2.

padding

Unit vector with four elements specifying the top, right, bottom, -and left padding from the edges of the legend key to the edges of the key glyph.

- - -

Examples

-
library(ggplot2) - -set.seed(1233) -df <- data.frame( - x = sample(letters[1:2], 10, TRUE), - y = rnorm(10) -) +
+
rectangle_key_glyph(
+  colour = NA,
+  fill = fill,
+  alpha = alpha,
+  size = size,
+  linetype = linetype,
+  padding = unit(c(0, 0, 0, 0), "pt"),
+  color
+)
+
+circle_key_glyph(
+  colour = NA,
+  fill = fill,
+  alpha = alpha,
+  size = size,
+  linetype = linetype,
+  padding = unit(c(0, 0, 0, 0), "pt"),
+  color
+)
+
-ggplot(df, aes(x, y, color = x)) + - geom_boxplot( - key_glyph = rectangle_key_glyph(fill = color, padding = margin(3, 3, 3, 3)) - ) -
-ggplot(df, aes(x, y, color = x)) + - geom_boxplot( - key_glyph = circle_key_glyph( - fill = color, - color = "black", linetype = 3, size = 0.3, - padding = margin(2, 2, 2, 2) - ) - ) -
+
+

Arguments

+
colour, color
+

Unquoted name of the aesthetic to use for the outline color, +usually colour, color, or fill. Can also be a color constant, e.g. "red".

+ + +
fill
+

Unquoted name of the aesthetic to use for the fill color, +usually colour, color, or fill. Can also be a color constant, e.g. "red".

+ + +
alpha
+

Unquoted name of the aesthetic to use for alpha, +usually alpha. Can also be a numerical constant, e.g. 0.5.

+ + +
size
+

Unquoted name of the aesthetic to use for the line thickness of the +outline, usually size. Can also be a numerical constant, e.g. 0.5.

+ + +
linetype
+

Unquoted name of the aesthetic to use for the line type of the +outline, usually linetype. Can also be a constant, e.g. 2.

+ + +
padding
+

Unit vector with four elements specifying the top, right, bottom, +and left padding from the edges of the legend key to the edges of the key glyph.

+ +
+ +
+

Examples

+
library(ggplot2)
+
+set.seed(1233)
+df <- data.frame(
+  x = sample(letters[1:2], 10, TRUE),
+  y = rnorm(10)
+)
+
+ggplot(df, aes(x, y, color = x)) +
+  geom_boxplot(
+    key_glyph = rectangle_key_glyph(fill = color, padding = margin(3, 3, 3, 3))
+  )
+
+
+ggplot(df, aes(x, y, color = x)) +
+  geom_boxplot(
+    key_glyph = circle_key_glyph(
+      fill = color,
+      color = "black", linetype = 3, size = 0.3,
+      padding = margin(2, 2, 2, 2)
+    )
+  )
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/save_plot.html b/docs/reference/save_plot.html index bbd2d19..9366c6a 100644 --- a/docs/reference/save_plot.html +++ b/docs/reference/save_plot.html @@ -1,81 +1,18 @@ - - - - - - - -Alternative to ggsave(), with better support for multi-figure plots. — save_plot • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Alternative to ggsave(), with better support for multi-figure plots. — save_plot • cowplot - - - - - - - - - - + + - - - - -
-
- -
- -
+
-

This function replaces the standard ggsave() function for saving a plot into a file. It -has several advantages over ggsave(). First, it uses default sizes that work well with +

This function replaces the standard ggsave() function for saving a plot into a file. It +has several advantages over ggsave(). First, it uses default sizes that work well with the cowplot theme, so that frequently a plot size does not have to be explicitly specified. Second, it acknowledges that one often first develops individual plots and then combines them into -multi-plot figures, and it makes it easy---in combination with plot_grid()---to carry out +multi-plot figures, and it makes it easy---in combination with plot_grid()---to carry out this workflow. Finally, it makes it easy to adjust the aspect ratio of the figure, which is frequently necessary to accommodate plots with or without figure legend.

-
save_plot(
-  filename,
-  plot,
-  ncol = 1,
-  nrow = 1,
-  base_height = 3.71,
-  base_asp = 1.618,
-  base_width = NULL,
-  ...,
-  cols,
-  rows,
-  base_aspect_ratio,
-  width,
-  height
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
filename

Name of the plot file to generate.

plot

Plot to save.

ncol

Number of subplot columns.

nrow

Number of subplot rows.

base_height

The height (in inches) of the plot or of one sub-plot if nrow -or ncol > 1. Default is 3.71.

base_asp

The aspect ratio (width/height) of the plot or of one sub-plot if nrow +

+
save_plot(
+  filename,
+  plot,
+  ncol = 1,
+  nrow = 1,
+  base_height = 3.71,
+  base_asp = 1.618,
+  base_width = NULL,
+  ...,
+  cols,
+  rows,
+  base_aspect_ratio,
+  width,
+  height
+)
+
+ +
+

Arguments

+
filename
+

Name of the plot file to generate.

+ + +
plot
+

Plot to save.

+ + +
ncol
+

Number of subplot columns.

+ + +
nrow
+

Number of subplot rows.

+ + +
base_height
+

The height (in inches) of the plot or of one sub-plot if nrow +or ncol > 1. Default is 3.71.

+ + +
base_asp
+

The aspect ratio (width/height) of the plot or of one sub-plot if nrow or ncol > 1. This argument is used if base_width = NULL or if base_height = NULL; if both width and height are provided then the aspect ratio is ignored. -The default is 1.618 (the golden ratio), which works well for figures with a legend.

base_width

The width (in inches) of the plot or of one sub-plot if nrow +The default is 1.618 (the golden ratio), which works well for figures with a legend.

+ + +
base_width
+

The width (in inches) of the plot or of one sub-plot if nrow or ncol > 1. Default is NULL, which means that the width is calculated from -base_height and base_aspect_ratio.

...

Other arguments to be handed to ggsave2().

cols

Deprecated. Use ncol.

rows

Deprecated. Use nrow.

base_aspect_ratio

Deprecated. Use base_asp.

width

Deprecated. Don't use.

height

Deprecated. Don't use.

- -

Details

+base_height and base_aspect_ratio.

+ +
...
+

Other arguments to be handed to ggsave2().

+ + +
cols
+

Deprecated. Use ncol.

+ + +
rows
+

Deprecated. Use nrow.

+ + +
base_aspect_ratio
+

Deprecated. Use base_asp.

+ + +
width
+

Deprecated. Don't use.

+ + +
height
+

Deprecated. Don't use.

+ +
+
+

Details

The key idea for this function is that plots are often grids, with sup-plots at the individual grid locations. Therefore, for this function we specify a base width and aspect ratio that apply to one sup-plot, and we then specify how many rows and columns of subplots we have. This means that if we have code that can save a single figure, it is trivial to adapt this code to save a combination of multiple comparable figures. See examples for details.

+
-

Examples

-
# \donttest{ -library(ggplot2) - -# save a single plot with a legend -p1 <- ggplot(mpg, aes(x = cty, y = hwy, color = factor(cyl))) + - geom_point(size = 2) + - theme_half_open() - -file1 <- tempfile("file1", fileext = ".png") -file2 <- tempfile("file2", fileext = ".png") -save_plot(file1, p1) -# same as file1 but determine base_width given base_height -save_plot(file2, p1, base_height = NULL, base_width = 6) - -# save a single plot without legend, adjust aspect ratio -x <- (1:100)/10 -p3 <- ggplot(data.frame(x = x, y = x*sin(x)), aes(x, y)) + - geom_line() + - theme_minimal_hgrid() -file3 <- tempfile("file3", fileext = ".pdf") -save_plot(file3, p3, base_asp = 1.1) - -# now combine with a second plot and save -p3b <- ggplot(data.frame(x = x, y = cos(x)+x), aes(x, y)) + - geom_line() + - theme_minimal_hgrid() -p4 <- plot_grid(p3, p3b, labels = "AUTO") -file4 <- tempfile("file4", fileext = ".pdf") -save_plot(file4, p4, ncol = 2, base_asp = 1.1) -# } -
+
+

Examples

+
# \donttest{
+library(ggplot2)
+
+# save a single plot with a legend
+p1 <- ggplot(mpg, aes(x = cty, y = hwy, color = factor(cyl))) +
+  geom_point(size = 2) +
+  theme_half_open()
+
+file1 <- tempfile("file1", fileext = ".png")
+file2 <- tempfile("file2", fileext = ".png")
+save_plot(file1, p1)
+# same as file1 but determine base_width given base_height
+save_plot(file2, p1, base_height = NULL, base_width = 6)
+
+# save a single plot without legend, adjust aspect ratio
+x <- (1:100)/10
+p3 <- ggplot(data.frame(x = x, y = x*sin(x)), aes(x, y)) +
+ geom_line() +
+ theme_minimal_hgrid()
+file3 <- tempfile("file3", fileext = ".pdf")
+save_plot(file3, p3, base_asp = 1.1)
+
+# now combine with a second plot and save
+p3b <- ggplot(data.frame(x = x, y = cos(x)+x), aes(x, y)) +
+ geom_line() +
+ theme_minimal_hgrid()
+p4 <- plot_grid(p3, p3b, labels = "AUTO")
+file4 <- tempfile("file4", fileext = ".pdf")
+save_plot(file4, p4, ncol = 2, base_asp = 1.1)
+# }
+
+
+
-
- +
- - + + diff --git a/docs/reference/set_null_device.html b/docs/reference/set_null_device.html index 8702529..79a2148 100644 --- a/docs/reference/set_null_device.html +++ b/docs/reference/set_null_device.html @@ -1,77 +1,14 @@ - - - - - - - -Sets the null graphics device — set_null_device • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Sets the null graphics device — set_null_device • cowplot - - - - - - - - - - + + - - - - -
-
- -
- -
+
-

The function as_grob() needs to open a graphics device to render ggplot objects into +

The function as_grob() needs to open a graphics device to render ggplot objects into grid graphics objects. Unfortunately, there is no universally reliable graphics device available in R that always works. Therefore, this function allows you to switch out the null device.

-
set_null_device(null_device)
- -

Arguments

- - - - - - -
null_device

Either a string that defines the null device ("pdf", "png", "cairo", "agg") -or a function that returns a new graphics device.

+
+
set_null_device(null_device)
+
-

Details

+
+

Arguments

+
null_device
+

Either a string that defines the null device ("pdf", "png", "cairo", "agg") +or a function that returns a new graphics device.

+
+
+

Details

You need to be aware that some graphics devices cause side effects when used as null devices. If you use an interactive device as null device, you may see an empty plot window pop up. Similarly, if you use a graphics device that writes a file, then you may find temporary files associated -with the device. The default null device, pdf(NULL), does not cause these side effects. However, it has +with the device. The default null device, pdf(NULL), does not cause these side effects. However, it has has other limitations. For example, on OS X, it cannot use all the fonts that are available on the system. The ragg device can use all fonts, but it will create temporary files.

-

See also

- - - -

Examples

-
set_null_device("png") # set the png null device - -# create a jpeg null device -jpeg_null_device <- function(width, height) { - jpeg( - filename = tempfile(pattern = "jpeg_null_plot", fileext = ".jpg"), - width = width, height = height, units = "in", res = 96 - ) - dev.control("enable") -} -set_null_device(jpeg_null_device) -
+
+
+

See also

+ +
+ +
+

Examples

+
set_null_device("png") # set the png null device
+
+# create a jpeg null device
+jpeg_null_device <- function(width, height) {
+  jpeg(
+    filename = tempfile(pattern = "jpeg_null_plot", fileext = ".jpg"),
+    width = width, height = height, units = "in", res = 96
+   )
+  dev.control("enable")
+}
+set_null_device(jpeg_null_device)
+
+
+
-
- +
- - + + diff --git a/docs/reference/stamp-1.png b/docs/reference/stamp-1.png index d9c3c98..104b1bc 100644 Binary files a/docs/reference/stamp-1.png and b/docs/reference/stamp-1.png differ diff --git a/docs/reference/stamp-2.png b/docs/reference/stamp-2.png index 3dcd339..ef41710 100644 Binary files a/docs/reference/stamp-2.png and b/docs/reference/stamp-2.png differ diff --git a/docs/reference/stamp.html b/docs/reference/stamp.html index 7278e29..3b05a3b 100644 --- a/docs/reference/stamp.html +++ b/docs/reference/stamp.html @@ -1,75 +1,12 @@ - - - - - - - -Stamp plots with a label, such as good, bad, or ugly. — stamp • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Stamp plots with a label, such as good, bad, or ugly. — stamp • cowplot - - + + - - -
-
- -
- -
+
@@ -158,108 +80,107 @@

Stamp plots with a label, such as good, bad, or ugly.

Stamp plots with a label, such as good, bad, or ugly.

-
stamp(
-  p,
-  label,
-  color = "black",
-  alpha = 1,
-  vjust = 1.1,
-  hjust = 1,
-  size = 14,
-  family = "",
-  fontface = "bold",
-  clip = "on",
-  colour
-)
-
-stamp_good(p, ...)
-
-stamp_bad(p, ...)
-
-stamp_wrong(p, ...)
-
-stamp_ugly(p, ...)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
p

The plot to stamp

label

The text label used for the stamp

color, colour

The color of the stamp

alpha

Transparency level of the stamp

hjust, vjust

Horizontal and vertical adjustment of the label

size

Font size

family

Font family

fontface

Font face

clip

Should figure be clipped (default is "on")

...

Arguments handed off to stamp().

- - -

Examples

-
library(ggplot2) - -p <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + - geom_point(aes(color = factor(Petal.Width))) - -stamp_bad(p + guides(color = "none")) -
stamp_ugly(p) -
+
+
stamp(
+  p,
+  label,
+  color = "black",
+  alpha = 1,
+  vjust = 1.1,
+  hjust = 1,
+  size = 14,
+  family = "",
+  fontface = "bold",
+  clip = "on",
+  colour
+)
+
+stamp_good(p, ...)
+
+stamp_bad(p, ...)
+
+stamp_wrong(p, ...)
+
+stamp_ugly(p, ...)
+
+ +
+

Arguments

+
p
+

The plot to stamp

+ + +
label
+

The text label used for the stamp

+ + +
color, colour
+

The color of the stamp

+ + +
alpha
+

Transparency level of the stamp

+ + +
hjust, vjust
+

Horizontal and vertical adjustment of the label

+ + +
size
+

Font size

+ + +
family
+

Font family

+ + +
fontface
+

Font face

+ + +
clip
+

Should figure be clipped (default is "on")

+ + +
...
+

Arguments handed off to stamp().

+ +
+ +
+

Examples

+
library(ggplot2)
+
+p <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) +
+  geom_point(aes(color = factor(Petal.Width)))
+
+stamp_bad(p + guides(color = "none"))
+
+stamp_ugly(p)
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/theme_cowplot-1.png b/docs/reference/theme_cowplot-1.png index 1b9a7f5..898347c 100644 Binary files a/docs/reference/theme_cowplot-1.png and b/docs/reference/theme_cowplot-1.png differ diff --git a/docs/reference/theme_cowplot.html b/docs/reference/theme_cowplot.html index b854ad5..ab0d50f 100644 --- a/docs/reference/theme_cowplot.html +++ b/docs/reference/theme_cowplot.html @@ -1,77 +1,14 @@ - - - - - - - -Create the default cowplot theme — theme_cowplot • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Create the default cowplot theme — theme_cowplot • cowplot - - - - - - - - - - + + - - - - -
-
- -
- -
+
@@ -162,92 +84,94 @@

Create the default cowplot theme

the case.

-
theme_cowplot(
-  font_size = 14,
-  font_family = "",
-  line_size = 0.5,
-  rel_small = 12/14,
-  rel_tiny = 11/14,
-  rel_large = 16/14
-)
-
-theme_half_open(
-  font_size = 14,
-  font_family = "",
-  line_size = 0.5,
-  rel_small = 12/14,
-  rel_tiny = 11/14,
-  rel_large = 16/14
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - -
font_size

Overall font size.

font_family

Font family for plot title, axis titles and labels, legend texts, etc.

line_size

Line size for axis lines.

rel_small

Relative size of small text (e.g., axis tick labels)

rel_tiny

Relative size of tiny text (e.g., caption)

rel_large

Relative size of large text (e.g., title)

- -

Value

- -

The theme.

-

Details

+
+
theme_cowplot(
+  font_size = 14,
+  font_family = "",
+  line_size = 0.5,
+  rel_small = 12/14,
+  rel_tiny = 11/14,
+  rel_large = 16/14
+)
+
+theme_half_open(
+  font_size = 14,
+  font_family = "",
+  line_size = 0.5,
+  rel_small = 12/14,
+  rel_tiny = 11/14,
+  rel_large = 16/14
+)
+
+ +
+

Arguments

+
font_size
+

Overall font size.

+ + +
font_family
+

Font family for plot title, axis titles and labels, legend texts, etc.

+ + +
line_size
+

Line size for axis lines.

-

Both theme_cowplot() and theme_half_open() provide exactly the same styling.

-

Examples

-
library(ggplot2) +
rel_small
+

Relative size of small text (e.g., axis tick labels)

-ggplot(mtcars, aes(disp, mpg)) + - geom_point() + - theme_cowplot(font_size = 12) -
+ +
rel_tiny
+

Relative size of tiny text (e.g., caption)

+ + +
rel_large
+

Relative size of large text (e.g., title)

+ +
+
+

Value

+ + +

The theme.

+
+
+

Details

+

Both theme_cowplot() and theme_half_open() provide exactly the same styling.

+
+ +
+

Examples

+
library(ggplot2)
+
+ggplot(mtcars, aes(disp, mpg)) +
+  geom_point() +
+  theme_cowplot(font_size = 12)
+
+
+
+
-
- +

- - + + diff --git a/docs/reference/theme_map-1.png b/docs/reference/theme_map-1.png index 8fdb1fd..d28c727 100644 Binary files a/docs/reference/theme_map-1.png and b/docs/reference/theme_map-1.png differ diff --git a/docs/reference/theme_map-2.png b/docs/reference/theme_map-2.png index 7bb3035..8d021c3 100644 Binary files a/docs/reference/theme_map-2.png and b/docs/reference/theme_map-2.png differ diff --git a/docs/reference/theme_map.html b/docs/reference/theme_map.html index e10faac..74466f9 100644 --- a/docs/reference/theme_map.html +++ b/docs/reference/theme_map.html @@ -1,75 +1,12 @@ - - - - - - - -Create a theme for map plotting — theme_map • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Create a theme for map plotting — theme_map • cowplot + + - - - - -
-
- -
- -
+
@@ -158,84 +80,86 @@

Create a theme for map plotting

The theme created by this function is useful for plotting maps with cowplot default sizing.

-
theme_map(
-  font_size = 14,
-  font_family = "",
-  line_size = 0.5,
-  rel_small = 12/14,
-  rel_tiny = 11/14,
-  rel_large = 16/14
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - -
font_size

Overall font size. Default is 14.

font_family

Base font family.

line_size

Line size for axis lines.

rel_small

Relative size of small text (e.g., axis tick labels)

rel_tiny

Relative size of tiny text (e.g., caption)

rel_large

Relative size of large text (e.g., title)

- -

Value

- -

The theme.

- -

Examples

-
library(ggplot2) -library(maps) - -usa_data = map_data("usa") -ggplot(usa_data, aes(long, lat, fill = region)) + - geom_polygon() + theme_map() -
ggplot(usa_data, aes(long, lat, fill = region)) + - facet_wrap(~region, scales = "free") + - geom_polygon() + theme_map() -
+
+
theme_map(
+  font_size = 14,
+  font_family = "",
+  line_size = 0.5,
+  rel_small = 12/14,
+  rel_tiny = 11/14,
+  rel_large = 16/14
+)
+
+ +
+

Arguments

+
font_size
+

Overall font size. Default is 14.

+ + +
font_family
+

Base font family.

+ + +
line_size
+

Line size for axis lines.

+ + +
rel_small
+

Relative size of small text (e.g., axis tick labels)

+ + +
rel_tiny
+

Relative size of tiny text (e.g., caption)

+ + +
rel_large
+

Relative size of large text (e.g., title)

+ +
+
+

Value

+ + +

The theme.

+
+ +
+

Examples

+
library(ggplot2)
+library(maps)
+
+usa_data = map_data("usa")
+ggplot(usa_data, aes(long, lat, fill = region)) +
+  geom_polygon() + theme_map()
+
+ggplot(usa_data, aes(long, lat, fill = region)) +
+  facet_wrap(~region, scales = "free") +
+  geom_polygon() + theme_map()
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/theme_minimal_grid-1.png b/docs/reference/theme_minimal_grid-1.png index ea8c9d6..c788e6b 100644 Binary files a/docs/reference/theme_minimal_grid-1.png and b/docs/reference/theme_minimal_grid-1.png differ diff --git a/docs/reference/theme_minimal_grid-2.png b/docs/reference/theme_minimal_grid-2.png index 4866994..e7d0a9c 100644 Binary files a/docs/reference/theme_minimal_grid-2.png and b/docs/reference/theme_minimal_grid-2.png differ diff --git a/docs/reference/theme_minimal_grid-3.png b/docs/reference/theme_minimal_grid-3.png index 8d194fe..d81e0fd 100644 Binary files a/docs/reference/theme_minimal_grid-3.png and b/docs/reference/theme_minimal_grid-3.png differ diff --git a/docs/reference/theme_minimal_grid.html b/docs/reference/theme_minimal_grid.html index 718b591..fff4585 100644 --- a/docs/reference/theme_minimal_grid.html +++ b/docs/reference/theme_minimal_grid.html @@ -1,79 +1,16 @@ - - - - - - - -Minimalistic themes with grids — theme_minimal_grid • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Minimalistic themes with grids — theme_minimal_grid • cowplot - - - - - - - - - - - - + + - - -
-
- -
- -
+

Three minimalistic themes that provide either a full grid, -a horizontal grid, or a vertical grid. Similar to theme_minimal(), but with some +a horizontal grid, or a vertical grid. Similar to theme_minimal(), but with some stylistic differences. Most importantly, these themes do not draw minor grid lines. -Also, font sizes are coordinated with theme_half_open() and with the defaults -in the save_plot() function.

+Also, font sizes are coordinated with theme_half_open() and with the defaults +in the save_plot() function.

+
+ +
+
theme_minimal_grid(
+  font_size = 14,
+  font_family = "",
+  line_size = 0.5,
+  rel_small = 12/14,
+  rel_tiny = 11/14,
+  rel_large = 16/14,
+  color = "grey85",
+  colour
+)
+
+theme_minimal_vgrid(
+  font_size = 14,
+  font_family = "",
+  line_size = 0.5,
+  rel_small = 12/14,
+  rel_tiny = 11/14,
+  rel_large = 16/14,
+  color = "grey85",
+  colour
+)
+
+theme_minimal_hgrid(
+  font_size = 14,
+  font_family = "",
+  line_size = 0.5,
+  rel_small = 12/14,
+  rel_tiny = 11/14,
+  rel_large = 16/14,
+  color = "grey85",
+  colour
+)
-
theme_minimal_grid(
-  font_size = 14,
-  font_family = "",
-  line_size = 0.5,
-  rel_small = 12/14,
-  rel_tiny = 11/14,
-  rel_large = 16/14,
-  color = "grey85",
-  colour
-)
+    
+

Arguments

+
font_size
+

Overall font size.

+ + +
font_family
+

Font family for plot title, axis titles and labels, legend texts, etc.

-theme_minimal_vgrid( - font_size = 14, - font_family = "", - line_size = 0.5, - rel_small = 12/14, - rel_tiny = 11/14, - rel_large = 16/14, - color = "grey85", - colour -) -theme_minimal_hgrid( - font_size = 14, - font_family = "", - line_size = 0.5, - rel_small = 12/14, - rel_tiny = 11/14, - rel_large = 16/14, - color = "grey85", - colour -)
+
line_size
+

Line size for grid lines.

-

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
font_size

Overall font size.

font_family

Font family for plot title, axis titles and labels, legend texts, etc.

line_size

Line size for grid lines.

rel_small

Relative size of small text (e.g., axis tick labels)

rel_tiny

Relative size of tiny text (e.g., caption)

rel_large

Relative size of large text (e.g., title)

color, colour

Color of grid lines.

-

Details

+
rel_small
+

Relative size of small text (e.g., axis tick labels)

+ +
rel_tiny
+

Relative size of tiny text (e.g., caption)

+ + +
rel_large
+

Relative size of large text (e.g., title)

+ + +
color, colour
+

Color of grid lines.

+ +
+
+

Details

theme_minimal_grid() provides a minimal grid theme. theme_minimal_hgrid() strips down this theme even further and draws only horizontal lines, and theme_minimal_vgrid() does the same for vertical lines.

+
-

Examples

-
library(ggplot2) - -# theme_minimal_grid() -ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + - geom_point() + theme_minimal_grid() -
-# theme_minimal_hgrid() -ggplot(mtcars, aes(x = carb)) + - geom_bar(fill = "lightblue") + - scale_y_continuous(limits = c(0, 11.5), expand = c(0, 0)) + - theme_minimal_hgrid() -
-# theme_minimal_vgrid() -ggplot(mtcars, aes(x = carb)) + - geom_bar(fill = "lightblue") + - scale_y_continuous(limits = c(0, 11.5), expand = c(0, 0)) + - coord_flip() + - theme_minimal_vgrid() -
+
+

Examples

+
library(ggplot2)
+
+# theme_minimal_grid()
+ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
+  geom_point() + theme_minimal_grid()
+
+
+# theme_minimal_hgrid()
+ggplot(mtcars, aes(x = carb)) +
+  geom_bar(fill = "lightblue") +
+  scale_y_continuous(limits = c(0, 11.5), expand = c(0, 0)) +
+  theme_minimal_hgrid()
+
+
+# theme_minimal_vgrid()
+ggplot(mtcars, aes(x = carb)) +
+  geom_bar(fill = "lightblue") +
+  scale_y_continuous(limits = c(0, 11.5), expand = c(0, 0)) +
+  coord_flip() +
+  theme_minimal_vgrid()
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/theme_nothing-1.png b/docs/reference/theme_nothing-1.png index 80acf4e..c3004a0 100644 Binary files a/docs/reference/theme_nothing-1.png and b/docs/reference/theme_nothing-1.png differ diff --git a/docs/reference/theme_nothing.html b/docs/reference/theme_nothing.html index 2b9803f..21ab423 100644 --- a/docs/reference/theme_nothing.html +++ b/docs/reference/theme_nothing.html @@ -1,75 +1,12 @@ - - - - - - - -Create a completely empty theme — theme_nothing • cowplot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Create a completely empty theme — theme_nothing • cowplot - - - - + + -
-
- -
- -
+
@@ -158,61 +80,62 @@

Create a completely empty theme

The theme created by this function shows nothing but the plot panel.

-
theme_nothing(font_size = 14, font_family = "", rel_small = 12/14)
- -

Arguments

- - - - - - - - - - - - - - -
font_size

Overall font size. Default is 14.

font_family

Base font family.

rel_small

Relative size of small text

- -

Value

- -

The theme.

- -

Examples

-
library(ggplot2) - -ggplot(mtcars, aes(disp, mpg, color = cyl)) + - geom_point() + - theme_nothing() -
+
+
theme_nothing(font_size = 14, font_family = "", rel_small = 12/14)
+
+ +
+

Arguments

+
font_size
+

Overall font size. Default is 14.

+ + +
font_family
+

Base font family.

+ + +
rel_small
+

Relative size of small text

+ +
+
+

Value

+ + +

The theme.

+
+ +
+

Examples

+
library(ggplot2)
+
+ggplot(mtcars, aes(disp, mpg, color = cyl)) +
+  geom_point() +
+  theme_nothing()
+
+
+
+
-
- +
- - + + diff --git a/docs/sitemap.xml b/docs/sitemap.xml new file mode 100644 index 0000000..764308f --- /dev/null +++ b/docs/sitemap.xml @@ -0,0 +1,162 @@ + + + + /404.html + + + /ISSUE_TEMPLATE.html + + + /articles/aligning_plots.html + + + /articles/drawing_with_on_plots.html + + + /articles/index.html + + + /articles/introduction.html + + + /articles/mixing_plot_frameworks.html + + + /articles/plot_grid.html + + + /articles/shared_legends.html + + + /articles/themes.html + + + /authors.html + + + /index.html + + + /news/index.html + + + /reference/add_sub.html + + + /reference/align_margin.html + + + /reference/align_plots.html + + + /reference/as_grob.html + + + /reference/as_gtable.html + + + /reference/axis_canvas.html + + + /reference/background_grid.html + + + /reference/cowplot-package.html + + + /reference/cowplot.html + + + /reference/draw_figure_label.html + + + /reference/draw_grob.html + + + /reference/draw_image.html + + + /reference/draw_label.html + + + /reference/draw_line.html + + + /reference/draw_plot.html + + + /reference/draw_plot_label.html + + + /reference/draw_text.html + + + /reference/get_legend.html + + + /reference/get_panel.html + + + /reference/get_plot_component.html + + + /reference/get_title.html + + + /reference/get_y_axis.html + + + /reference/ggdraw.html + + + /reference/ggsave2.html + + + /reference/gtable_remove_grobs.html + + + /reference/gtable_squash_cols.html + + + /reference/gtable_squash_rows.html + + + /reference/index.html + + + /reference/insert_xaxis_grob.html + + + /reference/panel_border.html + + + /reference/plot_grid.html + + + /reference/png_null_device.html + + + /reference/rectangle_key_glyph.html + + + /reference/save_plot.html + + + /reference/set_null_device.html + + + /reference/stamp.html + + + /reference/theme_cowplot.html + + + /reference/theme_map.html + + + /reference/theme_minimal_grid.html + + + /reference/theme_nothing.html + +