R语言:yyplot画emoji和动物轮廓
2020-11-29 本文已影响0人
胡童远
导读
这里记录两个Y叔的绘图方法。可以画emoji的R包emojifont,可以画轮廓的ggimage geom_phylopic函数。
一、emojifont
emoji库:https://emojiterra.com/vegetables/
geom_emoji不支持大写
1 11.25西方感恩节吃火鸡
install.library("emojifont")
library("emojifont")
library("ggplot2")
ggplot() + geom_emoji('turkey', color="steelblue") +
labs(x="", y="") +
theme(axis.ticks = element_blank()) +
theme(axis.text = element_blank()) +
theme(axis.title = element_blank())

2 玫瑰rose
ggplot() + geom_emoji('rose', color="red") +
labs(x="", y="") +
theme(axis.ticks = element_blank()) +
theme(axis.text = element_blank()) +
theme(axis.title = element_blank())

3 蘑菇mushroom
ggplot() + geom_emoji('mushroom') +
labs(x="", y="") +
theme(axis.ticks = element_blank()) +
theme(axis.text = element_blank()) +
theme(axis.title = element_blank())

二、ggimage
1 准备
USA (IA) 镜像 + 翻墙 安装ggimage(无依赖)
HONGKONG 镜像 + 翻墙 安装rvcheck (ggimage依赖包)
GUANGZHOU 镜像 安装magick (ggimage依赖包)
2 耗子尾汁 rat tail solution
library("magick")
library("rvcheck")
library("ggimage")
options(phylopic_width=128)
mouse = 'Mus musculus'
id = phylopic_uid(mouse)
d = data.frame(x=0:1, y=0:1)
ggplot(d, aes(x=x, y=y)) +
geom_blank() +
geom_phylopic(aes(image=uid),
data=id,
x=.5, y=.5, size=.8
) +
geom_phylopic(aes(image=uid),
data=id,
x=.2, y=.85, size=.3,
colour = 'steelblue', angle=180
) +
labs(x=NULL, y=NULL,
title='耗子尾汁',
subtitle = '做学术要讲伦理')

3 猫咪
options(phylopic_width=128) # 抓的是128px的图,其他数字报错哦
sth = 'Felis catus' # 科学名
id = phylopic_uid(sth) # uid对应了相应的图
d = data.frame(x=0:1, y=0:1)
ggplot(d, aes(x=x, y=y)) +
geom_blank() +
geom_phylopic(aes(image=uid), data=id, x=.5, y=.5, size=.4, colour = 'steelblue')

4 火烈鸟
sth = 'Phoenicopteridae' # 科学名
id = phylopic_uid(sth) # uid对应了相应的图
d = data.frame(x=0:1, y=0:1)
ggplot(d, aes(x=x, y=y)) +
geom_blank() +
labs(x="", y="") +
theme(axis.ticks = element_blank()) +
theme(axis.text = element_blank()) +
theme(axis.title = element_blank()) +
geom_phylopic(aes(image=uid), data=id, x=.5, y=.5, size=.4, colour = 'red')
