ggthemes包——ggplot2绘图主题包

ggthemes包——ggplot2绘图主题包

这个包的原始地址为:jrnold/ggthemes。除了主题外,这个包还包含了很多颜色标度,具体可以参考该包的文档网站:ggthemes-docs

安装

1
devtools::install_github("jrnold/ggthemes")

主题

theme_base()

1
2
3
4
library(ggplot2)
library(ggthemes)
p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(.~am)
p + theme_base()

theme_calc()

1
p + theme_calc()

scale_color_calc():改变标度的颜色

1
p + theme_calc() + scale_color_calc()

scale_shape_calc():改变标度的形状

1
2
3
4
q <- ggplot(mtcars) +
geom_point(aes(x = wt, y = mpg, shape = factor(gear))) +
facet_wrap(~am)
q + theme_calc() + scale_shape_calc()

theme_economist()

1
p + theme_economist()

scale_colour_economist():改变标度的颜色

1
p + theme_economist() + scale_colour_economist()

对调坐标轴

1
2
3
p + theme_economist(horizontal = FALSE) +
scale_colour_economist() +
coord_flip()

theme_economist_white()

1
p + theme_economist_white()

scale_colour_economist():改变标度的颜色

1
p + theme_economist_white() + scale_colour_economist()

gray_bg = FALSE:使用全白背景

1
2
p + theme_economist_white(gray_bg = FALSE) +
scale_colour_economist()

base_family=”Verdana”:使用其它字体

1
2
3
library("extrafont")
p + theme_economist(base_family="Verdana") +
scale_colour_economist()

theme_excel()

1
p + theme_excel() + scale_colour_excel()

1
2
3
4
ggplot(mpg, aes(x = class, fill = drv)) +
geom_bar() +
scale_fill_excel() +
theme_excel()

theme_few()

1
p + theme_few() + scale_colour_few()

1
p + theme_few() + scale_colour_few("Light")

1
p + theme_few() + scale_colour_few("Dark")

1
2
3
4
ggplot(mtcars) +
geom_point(aes(x = wt, y = mpg, shape = factor(gear))) +
theme_few() +
scale_shape_few()

theme_fivethirtyeight()

1
p + theme_fivethirtyeight()

theme_foundation()

1
p + theme_foundation(base_size = 12, base_family = "")

theme_gdocs()

1
p + theme_gdocs() + scale_color_gdocs()

theme_hc()

1
p + theme_hc() + scale_colour_hc()

theme_hc()

1
2
p + theme_hc(style = "darkunica", base_family = "") +
scale_colour_hc("darkunica")

theme_igray()

1
p + theme_igray()

theme_map()

这个主题主要应用于地图:

1
2
3
4
5
6
7
8
9
library("maps")
library("ggplot2")
us <- fortify(map_data("state"), region = "region")
(gg <- ggplot() +
geom_map(data = us, map = us,
aes(x = long, y = lat, map_id = region, group = group),
fill = "white", color = "black", size = 0.25) +
coord_map("albers", lat0 = 39, lat1 = 45) +
theme_map())

theme_pander()

1
p + theme_pander()

1
2
3
require("pander")
panderOptions("graph.grid.color", "red")
p + theme_pander(base_family = "")

1
2
3
4
ggplot(mpg, aes(x = class, fill = drv)) +
geom_bar() +
scale_fill_pander() +
theme_pander(base_family = "")

theme_par()

1
p + theme_par()

1
2
par(font = 2, col.lab = "red", fg = "white", bg = "black")
p + theme_par()

theme_stata()

1
2
p + theme_stata() +
scale_colour_stata("s2color")

1
2
p + theme_stata(scheme = "s1mono") +
scale_colour_stata("mono")

theme_tufte()

1
2
3
4
5
6
7
p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point() +
scale_x_continuous(breaks = extended_range_breaks()(mtcars$wt)) +
scale_y_continuous(breaks = extended_range_breaks()(mtcars$mpg)) +
ggtitle("Cars")
p + geom_rangeframe() +
theme_tufte()

1
2
p + geom_rug() +
theme_tufte(ticks = FALSE)

theme_wsj()

1
2
3
4
5
p <- ggplot(mtcars) +
geom_point(aes(x = wt, y = mpg, colour = factor(gear))) +
facet_wrap(~am) +
ggtitle("Diamond Prices")
p + scale_colour_wsj("colors6", "") + theme_wsj()

1
p + scale_colour_wsj("colors6", "") + theme_wsj(color = "gray")

# R

评论

程振兴

程振兴 @czxa.top
截止今天,我已经在本博客上写了659.4k个字了!

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×