cowplot: Streamlined Plot Theme and Plot Annotations for 'ggplot2'

> library(cowplot)

Attaching package: 'cowplot'
The following object is masked from 'package:ggplot2':

    ggsave

バージョン: 0.6.2


関数名 概略
add_sub Add annotation underneath a plot
background_grid Add/modify/remove the background grid in a ggplot2 plot
cowplot cowplot.
draw_figure_label Add a label to a figure
draw_grob Draw a grob.
draw_label Draw a text label or mathematical expression.
draw_line Draw a line.
draw_plot Draw a (sub)plot.
draw_plot_label Add a label to a plot
draw_text Draw text.
ggdraw Set up a drawing layer on top of a ggplot
ggsave Cowplot reimplementation of ggsave.
gtable_remove_grobs Remove named elements from gtable
gtable_squash_cols Set the width of given colums to 0.
gtable_squash_rows Set the height of given rows to 0.
panel_border Add/remove the panel border in a ggplot2 plot
plot_grid Arrange multiple plots into a grid
plot_theme Get theme of a ggplot2 plot
save_plot Alternative to ggsave, with better support for multi-figure plots.
switch_axis_position Switches the axis position of the x or y axis in a ggplot2 plot.
theme_cowplot Create the default cowplot theme
theme_nothing Create a completely empty theme

plot_theme

> p <- ggplot(mtcars, aes(mpg, disp)) + geom_line(colour = "blue")
> plot_theme(p)
$line
List of 4
 $ colour  : chr "black"
 $ size    : num 0.5
 $ linetype: num 1
 $ lineend : chr "butt"
 - attr(*, "class")= chr [1:2] "element_line" "element"

$rect
List of 4
 $ fill    : chr "transparent"
 $ colour  : logi NA
 $ size    : num 0
 $ linetype: num 0
 - attr(*, "class")= chr [1:2] "element_rect" "element"

$text
List of 10
 $ family    : chr ""
 $ face      : chr "plain"
 $ colour    : chr "black"
 $ size      : num 14
 $ hjust     : num 0.5
 $ vjust     : num 0.5
 $ angle     : num 0
 $ lineheight: num 0.9
 $ margin    :Classes 'margin', 'unit'  atomic [1:4] 0 0 0 0
  .. ..- attr(*, "valid.unit")= int 8
  .. ..- attr(*, "unit")= chr "pt"
 $ debug     : logi FALSE
 - attr(*, "class")= chr [1:2] "element_text" "element"

$axis.line
List of 4
 $ colour  : NULL
 $ size    : NULL
 $ linetype: NULL
 $ lineend : NULL
 - attr(*, "class")= chr [1:2] "element_line" "element"

$axis.line.x
List of 4
 $ colour  : chr "black"
 $ size    : num 0.5
 $ linetype: NULL
 $ lineend : NULL
 - attr(*, "class")= chr [1:2] "element_line" "element"

$axis.line.y
List of 4
 $ colour  : chr "black"
 $ size    : num 0.5
 $ linetype: NULL
 $ lineend : NULL
 - attr(*, "class")= chr [1:2] "element_line" "element"

$axis.text
List of 10
 $ family    : NULL
 $ face      : NULL
 $ colour    : chr "black"
 $ size      : num 12
 $ hjust     : NULL
 $ vjust     : NULL
 $ angle     : NULL
 $ lineheight: NULL
 $ margin    : NULL
 $ debug     : NULL
 - attr(*, "class")= chr [1:2] "element_text" "element"

$axis.text.x
List of 10
 $ family    : NULL
 $ face      : NULL
 $ colour    : NULL
 $ size      : NULL
 $ hjust     : NULL
 $ vjust     : num 1
 $ angle     : NULL
 $ lineheight: NULL
 $ margin    :Classes 'margin', 'unit'  atomic [1:4] 3 0 0 0
  .. ..- attr(*, "valid.unit")= int 8
  .. ..- attr(*, "unit")= chr "pt"
 $ debug     : NULL
 - attr(*, "class")= chr [1:2] "element_text" "element"

$axis.text.y
List of 10
 $ family    : NULL
 $ face      : NULL
 $ colour    : NULL
 $ size      : NULL
 $ hjust     : num 1
 $ vjust     : NULL
 $ angle     : NULL
 $ lineheight: NULL
 $ margin    :Classes 'margin', 'unit'  atomic [1:4] 0 3 0 0
  .. ..- attr(*, "valid.unit")= int 8
  .. ..- attr(*, "unit")= chr "pt"
 $ debug     : NULL
 - attr(*, "class")= chr [1:2] "element_text" "element"

$axis.ticks
List of 4
 $ colour  : chr "black"
 $ size    : num 0.5
 $ linetype: NULL
 $ lineend : NULL
 - attr(*, "class")= chr [1:2] "element_line" "element"

$axis.ticks.length
[1] 3.5pt

$axis.title.x
List of 10
 $ family    : NULL
 $ face      : NULL
 $ colour    : NULL
 $ size      : NULL
 $ hjust     : NULL
 $ vjust     : NULL
 $ angle     : NULL
 $ lineheight: NULL
 $ margin    :Classes 'margin', 'unit'  atomic [1:4] 6 0 3 0
  .. ..- attr(*, "valid.unit")= int 8
  .. ..- attr(*, "unit")= chr "pt"
 $ debug     : NULL
 - attr(*, "class")= chr [1:2] "element_text" "element"

$axis.title.y
List of 10
 $ family    : NULL
 $ face      : NULL
 $ colour    : NULL
 $ size      : NULL
 $ hjust     : NULL
 $ vjust     : NULL
 $ angle     : num 90
 $ lineheight: NULL
 $ margin    :Classes 'margin', 'unit'  atomic [1:4] 0 6 0 3
  .. ..- attr(*, "valid.unit")= int 8
  .. ..- attr(*, "unit")= chr "pt"
 $ debug     : NULL
 - attr(*, "class")= chr [1:2] "element_text" "element"

$legend.background
List of 4
 $ fill    : NULL
 $ colour  : logi NA
 $ size    : NULL
 $ linetype: NULL
 - attr(*, "class")= chr [1:2] "element_rect" "element"

$legend.margin
[1] 0.1cm

$legend.key
 list()
 - attr(*, "class")= chr [1:2] "element_blank" "element"

$legend.key.size
[1] 1lines

$legend.key.height
NULL

$legend.key.width
NULL

$legend.text
List of 10
 $ family    : NULL
 $ face      : NULL
 $ colour    : NULL
 $ size      :Class 'rel'  num 0.857
 $ hjust     : NULL
 $ vjust     : NULL
 $ angle     : NULL
 $ lineheight: NULL
 $ margin    : NULL
 $ debug     : NULL
 - attr(*, "class")= chr [1:2] "element_text" "element"

$legend.text.align
NULL

$legend.title
List of 10
 $ family    : NULL
 $ face      : NULL
 $ colour    : NULL
 $ size      : NULL
 $ hjust     : num 0
 $ vjust     : NULL
 $ angle     : NULL
 $ lineheight: NULL
 $ margin    : NULL
 $ debug     : NULL
 - attr(*, "class")= chr [1:2] "element_text" "element"

$legend.title.align
NULL

$legend.position
[1] "right"

$legend.direction
NULL

$legend.justification
[1] "center"

$legend.box
NULL

$panel.background
 list()
 - attr(*, "class")= chr [1:2] "element_blank" "element"

$panel.border
 list()
 - attr(*, "class")= chr [1:2] "element_blank" "element"

$panel.grid.major
 list()
 - attr(*, "class")= chr [1:2] "element_blank" "element"

$panel.grid.minor
 list()
 - attr(*, "class")= chr [1:2] "element_blank" "element"

$panel.margin
[1] 7pt

$panel.margin.x
NULL

$panel.margin.y
NULL

$panel.ontop
[1] FALSE

$strip.background
List of 4
 $ fill    : chr "grey80"
 $ colour  : chr "grey50"
 $ size    : num 0
 $ linetype: NULL
 - attr(*, "class")= chr [1:2] "element_rect" "element"

$strip.text
List of 10
 $ family    : NULL
 $ face      : NULL
 $ colour    : NULL
 $ size      :Class 'rel'  num 0.857
 $ hjust     : NULL
 $ vjust     : NULL
 $ angle     : NULL
 $ lineheight: NULL
 $ margin    : NULL
 $ debug     : NULL
 - attr(*, "class")= chr [1:2] "element_text" "element"

$strip.text.x
List of 10
 $ family    : NULL
 $ face      : NULL
 $ colour    : NULL
 $ size      : NULL
 $ hjust     : NULL
 $ vjust     : NULL
 $ angle     : NULL
 $ lineheight: NULL
 $ margin    :Classes 'margin', 'unit'  atomic [1:4] 7 0 7 0
  .. ..- attr(*, "valid.unit")= int 8
  .. ..- attr(*, "unit")= chr "pt"
 $ debug     : NULL
 - attr(*, "class")= chr [1:2] "element_text" "element"

$strip.text.y
List of 10
 $ family    : NULL
 $ face      : NULL
 $ colour    : NULL
 $ size      : NULL
 $ hjust     : NULL
 $ vjust     : NULL
 $ angle     : num -90
 $ lineheight: NULL
 $ margin    :Classes 'margin', 'unit'  atomic [1:4] 0 7 0 7
  .. ..- attr(*, "valid.unit")= int 8
  .. ..- attr(*, "unit")= chr "pt"
 $ debug     : NULL
 - attr(*, "class")= chr [1:2] "element_text" "element"

$strip.switch.pad.grid
[1] 0.1cm

$strip.switch.pad.wrap
[1] 0.1cm

$plot.background
 list()
 - attr(*, "class")= chr [1:2] "element_blank" "element"

$plot.title
List of 10
 $ family    : NULL
 $ face      : chr "bold"
 $ colour    : NULL
 $ size      : num 14
 $ hjust     : NULL
 $ vjust     : NULL
 $ angle     : NULL
 $ lineheight: NULL
 $ margin    :Classes 'margin', 'unit'  atomic [1:4] 0 0 7 0
  .. ..- attr(*, "valid.unit")= int 8
  .. ..- attr(*, "unit")= chr "pt"
 $ debug     : NULL
 - attr(*, "class")= chr [1:2] "element_text" "element"

$plot.margin
[1] 7pt 7pt 7pt 7pt

switch_axis_position

> p <- ggplot(mtcars, aes(mpg, disp)) + geom_line(colour = "blue")
> ggdraw(switch_axis_position(p, axis = 'y'))

theme_cowplot

> ggplot(mtcars, aes(mpg, disp)) + 
+   geom_point() +
+   theme_cowplot()

theme_nothing

枠を描画しない

> ggplot(mtcars, aes(mpg, disp)) + 
+   geom_point() + 
+   theme_nothing() + 
+   labs(x = NULL, y = NULL)