可视化系列【四】:跟着Nature Communications
2023-03-31 本文已影响0人
Bio_Infor
不积跬步,无以至千里
本期我们尝试复现2023年3月31日发表在Nature Communications上的TRABID overexpression enables synthetic lethality to PARP inhibitor via prolonging 53BP1 retention at double-strand breaks文章中的Fig1b
。
![](https://img.haomeiwen.com/i26593565/e3add050959bf765.png)
以下是原图:
![](https://img.haomeiwen.com/i26593565/a810ff7ac56f30e6.png)
数据可以自行下载,也可评论区留言我私发给你。
代码
dir.create('Fig')
#-- install packages
if (!requireNamespace('ggbeeswarm')){
install.packages('ggbeeswarm')
}
library(ggplot2)
library(ggbeeswarm)
library(dplyr)
library(tidyr)
library(magrittr)
library(forcats)
library(readr)
#-- load data
data <- read_csv(file = 'data.csv',
col_names = TRUE)
head(data)
#clean data
data <- data %>%
pivot_longer(cols = starts_with('sh'),
names_to = 'class')
head(data)
upper.75 <- function(x)mean(x) + sd(x)
lower.75 <- function(x)mean(x) - sd(x)
segment.data <- data %>%
group_by(class) %>%
summarise(mean = mean(value)) %>%
mutate(xmin = 1:5 - 0.3,
xmax = 1:5 + 0.3)
data %>%
mutate(class = fct_relevel(class, c('shControl', 'shUSP16', 'shUSP19', 'shUSP32', 'shZRANB1'))) %>%
ggplot(aes(x = class, y = value)) +
geom_beeswarm(aes(color = class), size = 0.1) +
scale_color_manual(values = c('#5659EA', '#11B77D', '#FEA647', '#F98180', '#DF8DFB')) +
stat_summary(color = 'black',
geom = 'errorbar',
fun.min = lower.75,
fun.max = upper.75,
width = .3,
linewidth = .3) +
geom_segment(data = segment.data,
aes(x = xmin, xend = xmax, y = mean, yend = mean),
linewidth = .7) +
scale_y_continuous(limits = c(0, 100),
expand = c(0, 0),
breaks = seq(from = 0, to = 100, by = 20)) +
scale_x_discrete(labels = c('shControl', 'shUSP16#2', 'shUSP19#2', 'shUSP32#2', 'shTRABID#1')) +
labs(x = NULL, y = '53BP1 foci number per U2OS cell') +
theme_classic() +
annotate(geom = 'text', label = 'n.s.', x = 2.5, y = 98, family = 'sans', color = 'black', size = 4) +
annotate(geom = 'text', label = 'P<0.0001', x = 5, y = 57, family = 'sans', color = 'black', size = 3.4) +
annotate(geom = 'segment', x = .95, xend = 4.05, y = 92, yend = 92, linewidth = .8) +
theme(legend.position = 'none',
axis.text = element_text(family = 'sans',
color = 'black',
size = 12),
axis.text.x = element_text(angle = 45,
hjust = 1,
vjust = 1),
axis.title.y = element_text(family = 'sans',
color = 'black',
size = 12),
axis.ticks = element_line(colour = 'black', linewidth = .8),
axis.ticks.length = unit(0.05, 'in'),
axis.line = element_line(colour = 'black', linewidth = .8))
ggsave(filename = 'Fig/Fig1b.jpeg', width = 3, height = 3.6, dpi = 5000)
最终效果
![](https://img.haomeiwen.com/i26593565/5888027e20ef5c0b.jpeg)
写在最后
-
原始图中
errorbar
只显示了一半,这可以通过geom_segment()
来实现,但在这里我没有做。 -
关于原图中的
P
如何显示成为P
,目前我还没有找到一个好办法。