
week2.jpg
整個新系列。目前的幾個系列, #R實戰(zhàn) 以生信分析為主, #跟著CNS學作圖 以復現(xiàn)頂刊Figure為主,而本系列 #R繪圖 則是學習不在文章中但同樣很好看的圖,致力于給同學們在數(shù)據(jù)可視化中提供新的思路和方法。
22
本期圖片

2022_16.png
示例數(shù)據(jù)和代碼領(lǐng)取
繪制
## 本圖可用于兩組的基因、蛋白、物種豐度等的對比 或隨時間的變化發(fā)展
rm(list = ls())
library(tidyverse)
library(ggtext)
library(showtext)
library(ggplot2)
showtext_opts(dpi = 300)
showtext_auto(enable = TRUE)
# Font
font_add_google("Roboto Mono")
f1 = "Roboto Mono"
df = read.csv("df_plot.csv")
# 兩組相同的部分(即先篩選出出現(xiàn)頻率為2的部分)
selected = df %>% select(definition, g) %>%
count(definition) %>%
filter(n==2) %>%
pull(definition)
# Plot
# 注意scico,cowplot,ggnewscaled包是否安裝
df %>%
ggplot(aes(x=g, y=rank)) +
geom_text(aes(label=definition, hjust=ifelse(g==1,1,0)), family=f1) +
geom_line(data=df %>% filter(definition %in% selected),
aes(group=definition)) +
geom_segment(data=df %>% filter(g==2),
aes(x=g+.8, xend=g+.8+pct*600, y=rank, yend=rank, color=pct), size=5) +
geom_segment(data=df %>% filter(g==1),
aes(x=g-.8, xend=g-.8-pct*600, y=rank, yend=rank, color=pct), size=5) +
scico::scale_color_scico(palette="bamako", direction=-1) +
ggnewscale::new_scale_color() +
geom_text(data=df %>% filter(g==2),
aes(x=g+0.85, y=rank, color=I(ifelse(pct>0.0015,"white","black")),
label=scales::percent(pct, accuracy = .01)),
size=3, hjust=0) +
ggnewscale::new_scale_color() +
geom_text(data=df %>% filter(g==1),
aes(x=g-0.85, y=rank, color=I(ifelse(pct>0.0014,"white","black")),
label=scales::percent(pct, accuracy = .01)),
size=3, hjust=1) +
annotate(geom="text",y=-.3,x=0.68, label="Big Dave's",size=4.3, fontface="bold") +
annotate(geom="text",y=-.3,x=2.2, label="Times",size=4.3, fontface="bold") +
scale_y_reverse() +
scale_x_continuous(limits=c(-1.5,4.5), expand=c(0,0)) +
cowplot::theme_map(13) +
theme(legend.position = "none",
plot.margin=margin(.5,.5,.3,.5, unit="cm"),
plot.title=element_text(size=15, hjust=.5),
plot.subtitle = element_text(hjust=.5),
plot.caption=element_text(size=8.5)) +
labs(caption="#MZBJ week 2 | Data from Cryptics.georgeho.org",
title="20 most common crossword puzzle definitions",
subtitle="from Big Dave's (2009-02-27 to 2022-04-15) and Times (2012-12-27 to 2021-09-12)")
ggsave("2022_16.png", height=6, width=8, bg="#fafafa")
參考
往期內(nèi)容
- (免費教程+代碼領(lǐng)取)|跟著Cell學作圖系列合集
- Q&A | 如何在論文中畫出漂亮的插圖?
- Front Immunol 復現(xiàn) | 1. GEO數(shù)據(jù)下載及sva批次校正(PCA可視化)
- R繪圖 | 氣泡散點圖+擬合曲線