論文
A latitudinal gradient of deep-sea invasions for marine fishes
https://www.nature.com/articles/s41467-023-36501-4
s41467-023-36501-4.pdf
論文中對應(yīng)的圖實(shí)現(xiàn)的代碼都有橱乱,鏈接是
https://github.com/stfriedman/Depth-transitions-paper
今天的推文我們重復(fù)一下論文中的figure1A,其中一個堆積柱形圖和一個啞鈴圖蜕劝,啞鈴圖就是點(diǎn)和線段的組合
首先是右側(cè)啞鈴圖
部分示例數(shù)據(jù)截圖
有一些分組數(shù)據(jù)論文中沒有提供昵时,這部分?jǐn)?shù)據(jù)我就隨便構(gòu)造了,最終的出圖不會和論文中完全一致
加載用到的R包
library(readxl)
library(tidyverse)
library(wesanderson)
讀取數(shù)據(jù)
fig1_data<-read_excel("data/20230302/41467_2023_36501_MOESM7_ESM.xlsx")
fig1_data %>% dim()
給數(shù)據(jù)集添加兩列分組
fig1_data %>%
mutate(cat=sample(c("small","norm","big"),46,replace = TRUE),
col=sample(c("Above expectation",
"Within expectation",
"Below expctation"),
46,replace = TRUE)) -> fig1_data
作圖代碼
ggplot(fig1_data, aes(x = family, y = trans_num)) +
geom_segment(aes(x = family, xend = family, y = sim_0.05, yend = sim_0.95),
col = "grey90", lwd = 3, lineend = "round"
) +
geom_segment(aes(x = family, xend = family, y = sim_median, yend = trans_num),
col = "grey50", lwd = 0.6
) +
geom_point(aes(x = family, y = sim_median),
pch = 21,
fill = "white", col = "grey50", size = 3, stroke = 1
) +
geom_point(size = 3.3,aes(color=col)) +
theme_classic() +
theme(
axis.text.y = element_blank(),
plot.margin = unit(c(0, 0.4, 0, 0), "cm"),
panel.grid.major.x = element_blank(),
panel.border = element_blank(),
panel.grid.major.y = element_line(size = 0.4),
axis.line.x = element_line(size = 0.2),
axis.line.y = element_blank(),
axis.ticks.x = element_line(size = 0.1),
axis.ticks.y = element_blank(),
legend.position = c(0.8,0.1),
legend.background = element_rect(color="black",fill="transparent"),
legend.title = element_blank(),
axis.title = element_text(size = 12),
axis.title.y = element_blank()
) +
coord_flip() +
ylab("Number of Transitions") +
labs(col = "Speciation Rate") +
scale_color_manual(values = c(
wes_palette("Darjeeling1")[2], "grey40",
wes_palette("Darjeeling1")[3]
)) -> p1
p1
堆積柱形圖
這個數(shù)據(jù)論文中沒有提供忱辅,這里我們隨便構(gòu)造數(shù)據(jù)
df1<-data.frame(x=rep(fig1_data$family,3),
y1=c(rep(c("Shallow","Deep","Intermediate"),each=46)),
y2=sample(1:100,46*3,replace = TRUE))
df1 %>% head()
準(zhǔn)備顏色
depth_cols <- setNames(
c("powderblue", "#2C8EB5", "#16465B"),
c("Shallow", "Intermediate", "Deep")
)
作圖代碼
ggplot(data=df1,
aes(y = y2, x = x)) +
geom_bar(position = "fill", stat = "identity", width = 0.7,
aes(fill=y1)) +
coord_flip() +
theme_classic() +
theme(
#axis.text.y = element_text(colour = famcol),
axis.text.x = element_blank(),
axis.ticks = element_blank(),
axis.line = element_blank(),
legend.position = "bottom",
legend.justification = c(0,0),
legend.key.size = unit(2,'mm'),
legend.title = element_blank(),
legend.background = element_rect(color="black",fill="transparent")
) +
xlab("") +
ylab("") +
guides(fill=guide_legend(ncol = 2))+
scale_fill_manual(values = depth_cols) -> p2
p2
最后是拼圖
library(patchwork)
p2+p1+
plot_layout(widths = c(1,5))
示例數(shù)據(jù)和代碼可以給推文點(diǎn)贊郎楼,然后點(diǎn)擊在看,最后留言獲取
歡迎大家關(guān)注我的公眾號
小明的數(shù)據(jù)分析筆記本
小明的數(shù)據(jù)分析筆記本 公眾號 主要分享:1、R語言和python做數(shù)據(jù)分析和數(shù)據(jù)可視化的簡單小例子举哟;2、園藝植物相關(guān)轉(zhuǎn)錄組學(xué)迅矛、基因組學(xué)妨猩、群體遺傳學(xué)文獻(xiàn)閱讀筆記;3秽褒、生物信息學(xué)入門學(xué)習(xí)資料及自己的學(xué)習(xí)筆記壶硅!
微信公眾號好像又有改動,如果沒有將這個公眾號設(shè)為星標(biāo)的話销斟,會經(jīng)常錯過公眾號的推文庐椒,個人建議將 小明的數(shù)據(jù)分析筆記本 公眾號添加星標(biāo),添加方法是