其他
好享学丨高人竟在我身边!R可视化终极指南大放送。ggthemr、gsci、tvthemes助您绘制靓丽美图
好享学是高下制图推出的数据可视化经验分享栏目,我们将定期与您分享各界优秀人士的制图经验,一同学习。
本文目录
ggthemr
ggthemr函数
ggthemr使用
提取ggthemr主题颜色为己用
ggthemr所有主题展示
flat
flat dark
camoflauge
chalk
copper
dust
earth
fresh
grape
grass
greyscale
light
lilac
pale
sea
sky
solarized
ggsci
ggsci所有主题函数
ggsci主题使用
提取ggsci主题颜色为己用
ggsci所有主题展示
tvthemes
tvthemes主题使用
tvthemes主题其它样式展示
ggthemr
ggthemr函数
一般情况下只会设置palette 参数,指定主题名称,其它均为默认参数【即每种主题的字号,磅值,图边距等均可修改】。
> ggthemr
function (
palette = "dust", #设置主题名称
layout = "clear", #其它参数一般保持默认,感兴趣的小伙伴可自行实验
spacing = 1,
text_size = 12,
type = "inner",
line_weight = 0.5,
pos = 1,
envir = as.environment(pos),
set_theme = TRUE)
{。。。。。。。。。。。。。。。。
}
ggthemr使用
library(ggthemr)
options(repr.plot.width = 4.5, repr.plot.height = 3, repr.plot.res = 300)
ggthemr('grape')
ggplot(mpg, aes(manufacturer, hwy)) + geom_boxplot() + ggtitle('flat')+theme(axis.text.x = element_text(angle = 45))
ggthemr_reset()
ggplot(mpg, aes(manufacturer, hwy)) + geom_boxplot() + theme(axis.text.x = element_text(angle = 45))
提取ggthemr主题颜色为己用
library(ggthemr)
ggthemr('grape')
swatch()#提取主题grape的所有颜色存储在列表中
library("scales")
show_col(swatch())#可视化swatch提取出的颜色
ggthemr所有主题展示
ggthemr具有17种主题,如下flat, flat dark, dust, light, earth, fresh, chalk, lilac, carrot, pale, copper, grape, greyscale, sky, solarized, grass, sea, camoflauge,以下为各种主题样式。
flat
flat dark
camoflauge
chalk
copper
dust
earth
fresh
grape
grass
greyscale
light
lilac
pale
sea
sky
solarized
ggsci
ggsci所有主题函数
ggsci提供如下几方面主题:
scientific journals, data visualization libraries, science fiction movies, and TV shows,共计18种主题如下:
ggsci主题使用
以The New England Journal of Medicine杂志配色主题为例。
library("ggsci")
library("ggplot2")
library("gridExtra")
options(repr.plot.width = 7.5, repr.plot.height = 4, repr.plot.res = 300)
data("diamonds")
p1 = ggplot(subset(diamonds, carat >= 2.2),
aes(x = table, y = price, colour = cut)) +
geom_point(alpha = 0.7) +
geom_smooth(method = "loess", alpha = 0.05, size = 1, span = 1) +
theme_bw()
p2 = ggplot(subset(diamonds, carat > 2.2 & depth > 55 & depth < 70),
aes(x = depth, fill = cut)) +
geom_histogram(colour = "black", binwidth = 1, position = "dodge") +
theme_bw()
#使用NEJM杂志主题
p1_nejm = p1 + scale_color_nejm()
p2_nejm = p2 + scale_fill_nejm()
grid.arrange(p1,p2,p1_nejm, p2_nejm, ncol = 2)
以下绿色框为ggplot2默认主题,红色框为ggsci中的NEJM主题
提取ggsci主题颜色为己用
mypal = pal_nejm("default", alpha = 1)(9)
library("scales")
show_col(mypal)#可视化色号
mypal#输出色号
ggsci所有主题展示
tvthemes
tvthemes主题使用
以Stannis色盘为例,Game of Thrones/A Song of Ice & Fire: ‘The Palettes of Ice & Fire’ (currently: Stark, Baratheon (Stannis), Lannister, Tully, Targaryen, Martell, Greyjoy, Tyrell, Arryn, Manderly)
#scale_fill_westeros
ggplot(mpg, aes(displ)) +
geom_histogram(aes(fill = class), col = "black", size = 0.1) +
scale_fill_westeros(palette = "Stannis", n = 7, reverse = TRUE) +
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0)) +
labs(title = glue("
We do not choose our destinies.
Yet we must... we must do our duty, no?
Great or small, we must do our duty."),
subtitle = "I will have no burnings. Pray Harder.",
caption = glue("
The Iron Throne is Mine by Right.
- Stannis Baratheon"),
x = "Bent Knees", y = "Lightbringer") +
theme_minimal() +
theme(text = element_text(family = "Cinzel", size = 20),
plot.title = element_text(family = "Cinzel", size = 26),
plot.subtitle = element_text(size = 18),
plot.caption = element_text(size = 16),
axis.text = element_text(size = 18),
legend.position = "none")
tvthemes主题其它样式展示
tvthemes提取影视剧主题色制作主题或色盘,如下:
Avatar: The Last Airbender: theme + palettes (Fire Nation, Water Tribe, Earth Kingdom, & Air Nomads) Brooklyn Nine-Nine: theme + palettes (regular & dark) Game of Thrones/A Song of Ice & Fire: ‘The Palettes of Ice & Fire’ (currently: Stark, Baratheon (Stannis), Lannister, Tully, Targaryen, Martell, Greyjoy, Tyrell, Arryn, Manderly) Rick & Morty: theme + palette Parks & Recreation: two themes (light & dark) + palette The Simpsons: theme + palette Spongebob Squarepants: theme + palette + background images Hilda: Day, Dusk, Night themes + palettes Attack on Titan: palette Kim Possible: palette Big Hero 6: palette Gravity Falls: palette More in future releases… Development branch: TBD…
颜色非常靓丽
END
往期推荐
点击上方蓝字关注我们