rance jeffries
rance jeffries

Reputation: 215

Are there any "inspection" type functions in ggplot2?

In grid graphics there's a nice little function get.gpar() that prints the current graphic's parameters (things like fill, color, etc.). And I'm just curious if any similar sorts of convenience functions exist in ggplot2?

Here's a dumb example of get.gpar() if you haven't encountered it before:

library(grid)
grid.newpage()
get.gpar()  #prints default settings

pushViewport(viewport(gp = gpar(fill = "red")))  #change fill to red
get.gpar("fill")  #now the default "white" should've changed to "red" 

Thanks!

Upvotes: 1

Views: 201

Answers (1)

IRTFM
IRTFM

Reputation: 263451

Looking at ?theme we see a reference to ?theme_update which also describes the theme_get function:

names(theme_get())
 [1] "line"                  "rect"                 
 [3] "text"                  "axis.title.x"         
 [5] "axis.title.x.top"      "axis.title.y"         
 [7] "axis.title.y.right"    "axis.text"      
# sniped the rest of the 57 item list of names in the current theme.

Like the lattice plotting system that preceded ggplot/ggplot2 the attributes of those theme types are held in lists, sometimes with attributes. The actual values of a few of them can be seen with:

> head( theme_get() )
$line
List of 6
 $ colour       : chr "black"
 $ size         : num 0.5
 $ linetype     : num 1
 $ lineend      : chr "butt"
 $ arrow        : logi FALSE
 $ inherit.blank: logi TRUE
 - attr(*, "class")= chr [1:2] "element_line" "element"

$rect
List of 5
 $ fill         : chr "white"
 $ colour       : chr "black"
 $ size         : num 0.5
 $ linetype     : num 1
 $ inherit.blank: logi TRUE
 - attr(*, "class")= chr [1:2] "element_rect" "element"

The help page for ?theme_set shows how to replace either single items with +.element inside the list or replace an entire list with %+replace%.element. Work the examples on the page to get a better understanding.

Upvotes: 3

Related Questions