Emojifont
FUN
library(ggimage) library(emojifont) library(ggtree) |
Emojifont
library(emojifont) search_emoji('smile') |
## [1] "smiley" "smile" "sweat_smile" "smiley_cat" "smile_cat" |
emoji(search_emoji('smile')) |
## [1] "<f0><U+009F><U+0098><U+0083>" "<f0><U+009F><U+0098><U+0084>" ## [3] "<f0><U+009F><U+0098><U+0085>" "<f0><U+009F><U+0098><U+00BA>" ## [5] "<f0><U+009F><U+0098><U+00B8>" |
set.seed(123) x <- rnorm(10) set.seed(321) y <- rnorm(10) plot(x, y, cex=0) text(x, y, labels=emoji('cow'), cex=1.5, col='steelblue', family='EmojiOne') |
d <- data.frame(x=x, y=y, label = sample(c(emoji('cow'), emoji('camel')), 10, replace=TRUE), type = sample(LETTERS[1:3], 10, replace=TRUE)) library("ggplot2") ggplot(d, aes(x, y, color=type, label=label)) + geom_text(family="EmojiOne", size=6) |
ggplot() + geom_emoji("rose", color='steelblue') + theme_void() |
x = seq(0, 2*pi, length=30) y = sin(x) ggplot() + geom_emoji('heartbeat', x=x, y=y, size=10) |
set.seed(2016-03-09) fa <- fontawesome(c('fa-github', 'fa-weibo', 'fa-twitter', 'fa-android', 'fa-coffee')) d <- data.frame(x=rnorm(20), y=rnorm(20), label=sample(fa, 20, replace=T)) ggplot(d, aes(x, y, color=label, label=label)) + geom_text(family='fontawesome-webfont', size=6)+ xlab(NULL)+ylab(NULL) + theme(legend.text=element_text(family='fontawesome-webfont')) |
ggplot() + geom_fontawesome("fa-github", color='black') + theme_void() |
Phylomoji
library(ggtree) tree_text <- "(((((cow, (whale, dolphin)), (pig2, boar)), camel), fish), seedling);" x <- read.tree(text=tree_text) ggtree(x, linetype="dashed", color='firebrick') + xlim(NA, 7) + ylim(NA, 8.5) + geom_tiplab(aes(color=label), parse='emoji', size=14, vjust=0.25) + labs(title="phylomoji", caption="powered by ggtree + emojifont") |
p <- ggtree(x, layout='circular') + geom_tiplab2(aes(color=label), parse='emoji', size=12, vjust=0.25) print(p) |
open_tree(p, angle=60) %>% rotate_tree(-75) |
set.seed(123) tr <- rtree(30) ggtree(tr) + xlim(NA, 5) + geom_cladelabel(node=41, label="chicken", parse="emoji", fontsize=12, align=TRUE, color="firebrick") + geom_cladelabel(node=51, label="duck", parse="emoji", fontsize=12, align=TRUE, color="steelblue") + geom_cladelabel(node=32, label="family", parse="emoji", fontsize=12, align=TRUE, color="darkkhaki") |
ggimage
set.seed(2017-02-21) d <- data.frame(x = rnorm(10), y = rnorm(10), image = sample(c("https://www.rstudio.com/favicon.ico", "http://www.bioconductor.org/favicon.ico"), size=10, replace = TRUE) ) ggplot(d, aes(x, y)) + geom_image(aes(image=image), size=.05) |
ggplot(d, aes(x, y)) + geom_image(aes(image=image), size=.05, by='height') |
ggplot(d, aes(x, y)) + geom_image(image=d$image[1]) |
d$size=seq(.05, .15, length.out=10) ggplot(d, aes(x, y)) + geom_image(aes(image=image, size=I(size))) |
ggplot(d, aes(x, y)) + geom_image(aes(image=image), color="firebrick") |
ggplot(d, aes(x, y)) + geom_pokemon(aes(image=ifelse(x>0, 'pikachu', 'tauros')), size=.1) |
# set.seed(123) # iris2 <- iris[sample(1:nrow(iris), 30),] # model <- lm(Petal.Length ~ Sepal.Length, data=iris2) # iris2$fitted <- predict(model) # # ggplot(iris2, aes(x = Sepal.Length, y = Petal.Length)) + # geom_linerange(aes(ymin = fitted, ymax = Petal.Length), # colour = "purple") + # geom_abline(intercept = model$coefficients[1], # slope = model$coefficients[2]) + # geom_emoji(aes(image = ifelse(abs(Petal.Length-fitted) > 0.5, '1f622', '1f600'))) |
ggplot(d, aes(x, y)) + geom_phylopic(image = "500bd7c6-71c1-4b86-8e54-55f72ad1beca", size = .1) + geom_phylopic(image="0174801d-15a6-4668-bfe0-4c421fbe51e8", size=Inf, alpha=.6, color='steelblue') |
f <- system.file("extdata/medals.txt", package="ggimage") medals <- read.table(f, header=TRUE) p <- ggplot(medals, aes(Country, count)) + geom_col(aes(fill = medal), width = .8) p + geom_flag(y = -2, aes(image = code)) + coord_flip() + expand_limits(y = -2) + scale_fill_manual(values = c("Gold" = "gold", "Bronze" = "#cd7f32", "Silver" = "#C0C0C0")) |
d$icon=sample(c('power', 'wifi', 'pie-graph', 'usb'), 10, replace=TRUE) ggplot(d, aes(x,y)) + geom_icon(aes(image=icon)) |
library(tibble) dd <- data.frame(x=LETTERS[1:3], y=1:3) pie <- ggplot(dd, aes(x=1, y, fill=x)) + geom_bar(stat="identity", width=1) + coord_polar(theta="y") + theme_void() + theme(legend.position="none") + theme_transparent() df <- data_frame(x = sample(2:9), y = sample(2:9), width = sample(seq(0.5, 3, length.out=length(x))), pie = list(pie)) p <- ggplot(data=data.frame(x=c(0, 10), y=c(0, 10)), aes(x, y))+geom_blank() p + geom_subview(aes(x=x, y=y, subview=pie, width=width, height=width), data=df) |
# imgfile <- tempfile(, fileext=".png") # download.file("http://pictogram2.com/p/p1000/i/tn.png", destfile=imgfile, mode='wb') # img <- list(imgfile, imgfile) # names(img) <- c("18", "22") # inset(p, img) |
PhyloPic is a database that stores reusable silhouette images of organisms. ggtree supports downloading images from PhyloPic and annotating phylogenetic tree with the downloaded images.
pp <- ggtree(rtree(30)) %>% phylopic("79ad5f09-cf21-4c89-8e7d-0c82a00ce728", color="steelblue", alpha = .3) + geom_text2(aes(subset=!isTip, label=node), hjust=-.3) print(pp) |
pp %>% phylopic("bf5fe2c5-1247-4ed9-93e2-d5af255ec462", color="darkcyan", alpha=.8, node=52,width = .8) %>% phylopic("0aa36f67-a70a-473b-8553-b96214b7d371", color="darkcyan", alpha=.8, node=59,width=.2) |
REFERENCES
vignette("phylomoji", package="emojifont")browseVignettes("ggimage")- https://apps.timwhitlock.info/emoji/tables/unicode
- https://github.com/yixuan/showtext
- https://github.com/eosrei/twemoji-color-font (EmojiOne.ttf)
- https://github.com/MorbZ/OpenSansEmoji(OpenSansEmoji.ttf.ttf)
- https://github.com/FortAwesome/Font-Awesome(fontawesome-webfont.ttf)
- http://fontawesome.io/cheatsheet/
- https://www.webpagefx.com/tools/emoji-cheat-sheet/
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Comment






