theme2: an enhanced version of ggplot2::theme()

Description Usage Arguments Examples

View source: R/ggconf.R

Description

theme2() has an enhanced version of ggplot2::theme() in terms of: 1. no element_(text|line|rect|grob|blank) specification 2. partial match for each configuration (e.g. size by sz)

Usage

1

Arguments

...

theme element specification (see examples below)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
if (requireNamespace("ggplot2", quietly = TRUE)) {

library(ggplot2)
ggplot(mtcars) + geom_point(aes(wt, hp, color=as.factor(cyl))) +
  theme2(
    text(f="bold", z=24, fmly="Times New Roman"),
    pnl.bg(fill="white"),
    lgd.box.margin(.2, .2, .2, .2, "cm"),
    lgd.box.bg(c="black"),
    lgd.key(fill="white"),
    lgd.position("bottom"),
    lgd.txt(z=rel(.8)),
    lgd.title(fmly="Consolas", c="royalblue"),  
    axs.title(fmly="Consolas", c="royalblue"),  
    axs.title.y(angle=0, vjust=.5),             
    axs.txt(z=rel(1.1)),
    axs.line(arrow=arrow(type="open", angle=20), z=2),
    axs.tick(z=1),                              
    axs.tick.len(.5, "cm"),
    plt.subttl(f="plain", hjust=1),
    plt.margin(.3, .3, .3, .1, "inch")          
  )


ggplot(mtcars) + geom_point(aes(wt, hp, color=cyl)) +
   theme2(a.txt(family = c("Consolas", "Times")[1]))

# all of the following three generate the same plot

ggplot(mtcars) + geom_point(aes(wt, hp, color=cyl)) +
   theme(text = element_text(size=20, face="bold"),
   axis.line = element_line(size=2),
   legend.key = element_rect(color="black"))

ggplot(mtcars) + geom_point(aes(wt, hp, color=cyl)) +
   theme2(text(size=20, face="bold"), axis.line(size=2),
          legend.key(color="black"))

ggplot(mtcars) + geom_point(aes(wt, hp, color=cyl)) +
   theme2(txt(sz=20, f="bold"), aline(sz=2), l.key(c="black"))



}

caprice-j/ggconf documentation built on May 23, 2019, 11:33 p.m.