R语言可视化

可视化系列【三】:跟着Nature Communications

2023-03-06  本文已影响0人  Bio_Infor

不积跬步,无以至千里

本期我们尝试复现2023年3月7日发表在Nature Communications上的Non-canonical functions of SNAIL drive context-specific cancer progression文章中的Fig3a

以下是原图:


数据可以自行下载,也可评论区留言我私发给你。

代码

library(readr)
library(tidyr)
library(dplyr)
library(forcats)
library(magrittr)
library(ggplot2)
library(RColorBrewer)
library(ggtext)

data <- read_csv('Fig3a.csv')
head(data)
# A tibble: 3 × 6
#  No.                    `Grade 1` `Grade 2` `Grade 3` `Grade 4` Total
#  <chr>                      <dbl>     <dbl>     <dbl>     <dbl> <dbl>
#1 PKrasG12D/+                    5        13         6         8    32
#2 PKrasG12D/+;SnailKI/+          0         6         9         4    19
#3 PKrasG12D/+;SnailKI/KI         1         5        11         0    17
data %>% 
  pivot_longer(starts_with('Grade'), names_to = 'Class') %>% 
  mutate(Class = fct_relevel(Class, paste('Grade', rev(1:4), sep = " "))) %>% 
  ggplot(aes(x = No., y = value/Total)) + 
  geom_bar(aes(fill = Class), 
           position = 'stack', 
           stat = 'identity',
           color = 'black',
           width = 0.7,
           linewidth = 0.5) +
  scale_fill_manual(values = c('#084594', '#4292c6', '#9ecae1', '#deebf7')) + 
  scale_y_continuous(expand = c(0, 0),
                     breaks = seq(0, 1, 0.2),
                     labels = seq(0, 100, 20)) + 
  scale_x_discrete(labels = c('*PKras^G12D/+*', 
                              '*PKras^G12D/+*;*Snail^KI/+*',
                              '*PKras^G12D/+*;*Snail^KI/KI*')) +
  labs(x = '', y = 'Tumours (%)', title = 'PDAC') + 
  theme_classic() + 
  theme(plot.title = element_text(hjust = 0.5, family = 'sans', size = 13, color = 'black'),
        legend.title = element_blank(),
        axis.text.x = element_markdown(vjust = 1, hjust = 1, angle = 45),
        axis.text = element_text(family = 'sans', color = 'black', size = 12),
        axis.title = element_text(family = 'sans', color = 'black', size = 12),
        axis.ticks.length.x = unit(0, units = 'cm'),
        axis.ticks.y = element_line(colour = 'black'),
        axis.line = element_line(colour = 'black'))
ggsave(filename = 'Fig3a.jpeg', width = 3, height = 3.5, dpi = 5000)

最终效果

写在最后

这个图里面有几个我觉得是值得我们大家一起学习的:

上一篇下一篇

猜你喜欢

热点阅读