当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R ggplot2 ggtheme 完整的主题


这些是控制所有非数据显示的完整主题。如果您只需要调整现有主题的显示,请使用theme()

用法

theme_grey(
  base_size = 11,
  base_family = "",
  base_line_size = base_size/22,
  base_rect_size = base_size/22
)

theme_gray(
  base_size = 11,
  base_family = "",
  base_line_size = base_size/22,
  base_rect_size = base_size/22
)

theme_bw(
  base_size = 11,
  base_family = "",
  base_line_size = base_size/22,
  base_rect_size = base_size/22
)

theme_linedraw(
  base_size = 11,
  base_family = "",
  base_line_size = base_size/22,
  base_rect_size = base_size/22
)

theme_light(
  base_size = 11,
  base_family = "",
  base_line_size = base_size/22,
  base_rect_size = base_size/22
)

theme_dark(
  base_size = 11,
  base_family = "",
  base_line_size = base_size/22,
  base_rect_size = base_size/22
)

theme_minimal(
  base_size = 11,
  base_family = "",
  base_line_size = base_size/22,
  base_rect_size = base_size/22
)

theme_classic(
  base_size = 11,
  base_family = "",
  base_line_size = base_size/22,
  base_rect_size = base_size/22
)

theme_void(
  base_size = 11,
  base_family = "",
  base_line_size = base_size/22,
  base_rect_size = base_size/22
)

theme_test(
  base_size = 11,
  base_family = "",
  base_line_size = base_size/22,
  base_rect_size = base_size/22
)

参数

base_size

基本字体大小,以磅为单位。

base_family

基本字体系列

base_line_size

线元素的基本尺寸

base_rect_size

矩形元素的基本尺寸

细节

theme_gray()

带有灰色背景和白色网格线的标志性 ggplot2 主题,旨在将数据向前推进,同时使比较变得容易。

theme_bw()

经典的 dark-on-light ggplot2 主题。可能更适合使用投影仪显示的演示文稿。

theme_linedraw()

白色背景上只有各种宽度的黑色线条的主题,让人想起线条画。其用途与 theme_bw() 类似。请注意,这个主题有一些非常细的线条(<< 1 pt),一些期刊可能会拒绝。

theme_light()

主题类似于theme_linedraw(),但具有浅灰色的线条和轴,以将更多注意力引向数据。

theme_dark()

theme_light() 的深色表亲,具有相似的线条大小,但背景为深色。有助于突出彩色细线。

theme_minimal()

没有背景注释的简约主题。

theme_classic()

classic-looking 主题,有 x 和 y 轴线,没有网格线。

theme_void()

一个完全空洞的主题。

theme_test()

视觉单元测试的主题。理想情况下,除了新函数之外,它应该永远不会改变。

例子

mtcars2 <- within(mtcars, {
  vs <- factor(vs, labels = c("V-shaped", "Straight"))
  am <- factor(am, labels = c("Automatic", "Manual"))
  cyl  <- factor(cyl)
  gear <- factor(gear)
})

p1 <- ggplot(mtcars2) +
  geom_point(aes(x = wt, y = mpg, colour = gear)) +
  labs(
    title = "Fuel economy declines as weight increases",
    subtitle = "(1973-74)",
    caption = "Data from the 1974 Motor Trend US magazine.",
    tag = "Figure 1",
    x = "Weight (1000 lbs)",
    y = "Fuel economy (mpg)",
    colour = "Gears"
  )

p1 + theme_gray() # the default

p1 + theme_bw()

p1 + theme_linedraw()

p1 + theme_light()

p1 + theme_dark()

p1 + theme_minimal()

p1 + theme_classic()

p1 + theme_void()


# Theme examples with panels
# \donttest{
p2 <- p1 + facet_grid(vs ~ am)

p2 + theme_gray() # the default

p2 + theme_bw()

p2 + theme_linedraw()

p2 + theme_light()

p2 + theme_dark()

p2 + theme_minimal()

p2 + theme_classic()

p2 + theme_void()

# }
源代码:R/theme-defaults.R

相关用法


注:本文由纯净天空筛选整理自Hadley Wickham等大神的英文原创作品 Complete themes。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。