美文网首页
R绘图模板——柱状图+散点图+折线图+显著性!

R绘图模板——柱状图+散点图+折线图+显著性!

作者: iBioinformatics | 来源:发表于2023-05-18 12:09 被阅读0次

1、加载R包:

library(ggplot2) # Create Elegant Data Visualisations Using the Grammar of Graphics
library(reshape2) # Flexibly Reshape Data: A Reboot of the Reshape Package
library(tidyr) # Tidy Messy Data
library(dplyr) # A Grammar of Data Manipulation
library(ggsignif) # Significance Brackets for 'ggplot2'

2、加载绘图数据并进行数据处理:

#数据——ggplot自带的ToothGrowth数据
df <- ToothGrowth
df$dose <- as.factor(df$dose)
data <- df
#计算均值及标准差
df1 <- data%>% group_by(dose)%>%
  summarise(mean= mean(len), sd= sd(len))

3、绘图:


ggplot()+ 
  geom_bar(df1,mapping=aes(x=dose,y=mean), fill = "white",
           size = 1.5,color = c("#d20962","#f47721","#7ac143"),position="dodge",
           stat="identity",width = 0.6)+
  geom_errorbar(df1,mapping=aes(x = dose,ymin = mean-sd, ymax = mean+sd),
                width = 0.3,color = c("#d20962","#f47721","#7ac143"), size=1.5)+
  geom_jitter(df, mapping=aes(x=dose,y=len,fill = dose,color = dose,shape = dose),
              size = 2.5,width = 0.2,alpha=0.9)+ 
  geom_line(df1,mapping=aes(x=dose,y=mean,group=1),
            size=1,color="#00aee6")+
  geom_point(df1,mapping=aes(x=dose,y=mean),color="black",size=3,shape=8)+
  scale_color_manual(values = c("#d20962","#f47721","#7ac143"))+ 
  geom_signif(df,mapping=aes(x=dose,y=len), 
              comparisons = list(c("0.5", "1"),
                                 c("1","2"),
                                 c("0.5","2")),
              map_signif_level=T, 
              tip_length=c(0,0,0,0,0,0), 
              y_position = c(35,40,45), 
              size=1, textsize = 7, 
              test = "t.test")+
  scale_y_continuous(expand = c(0, 0), limit = c(0, 50))+
  theme_classic(base_line_size = 1)+
  theme(panel.grid=element_blank(),
        axis.text=element_text(color='black',size=13,face = "bold"),
        axis.title.y = element_text(color='black',size=15,face = "bold"),
        legend.text = element_text(color='black',size=13,face = "bold"),
        legend.title = element_blank(),
        legend.position = "none")+
  labs(x=NULL,y="Value")

相关文章

  • 2018-04-24

    matplotlib绘图 通常我们可以绘制折线图、饼状图、柱状图,用matplotlib绘制折线图、柱状图情况较多...

  • python数据分析目录

    Bokeh 1.绘图空间基本操作2.图表辅助参数设置3.散点图4.折线图与面积图5.bokeh绘制柱状图——堆叠图...

  • (10) python matplotlib

    本篇以代码的形式,展示了matpoltlib的几种常用图表,包括:折线图,柱状图,饼状图,散点图,三维散点图,实时...

  • matplotlib常见图表(plot,bar,pie,3d,s

    本篇以代码的形式,展示了matpoltlib的几种常用图表,包括:折线图,柱状图,饼状图,散点图,三维散点图,实时...

  • 2019-05-05《R语言》绘图之散点图自学笔记

    《R语言》绘图之散点图自学笔记散点图 Generic X-Y Plotting 语法: plot(x, y, .....

  • C#Chart修改图标类型

    Chart有散点图、折线图、饼图、柱状图、饼图、极坐标图等等,那么如何设置呢?如下代码:

  • 数据可视化的表现方式

    1、pie图(南丁格尔玫瑰图:半径不同的饼图)2、柱状图3、折线图4、散点图5、气泡图6、雷达图

  • 数据可视化图表ECharts

    介绍: ECharts提供了折线图、柱状图、散点图、饼图、K线图,以及地图、热力图、关系图等多种图表API,并支持...

  • 2019-01-18 ECharts

    今天接触了ECharts,ECharts 提供了常规的折线图、柱状图、散点图、饼图、K线图,用于统计的盒形图,用于...

  • 【R实战 中级方法】十一、中级绘图

    这里是佳奥!又到了绘图的章节! 本章将首先从散点图和散点图矩阵讲起,然后探索各种各样的折线图。接着,将回顾用于相关...

网友评论

      本文标题:R绘图模板——柱状图+散点图+折线图+显著性!

      本文链接:https://www.haomeiwen.com/subject/yeiwsdtx.html