ggplot:截断坐标轴的折线图(带误差线)

library("ggplot2")
library("ggbreak")
library(RColorBrewer)

# 主题 ----------------------------------------------------------------------

#自定义图表主题,对图表主题做精细调整;
top.mar=0.2
right.mar=0.2
bottom.mar=0.2
left.mar=0.2
#设置图例的位置、大小和样式,并对字体样式、坐标轴的粗细、颜色、刻度长度等进行限定;
##这里通过legend.position将图例置于绘图区域的左上方;
mytheme<-theme_classic()+
  theme(text=element_text(family = "sans",colour ="black",size = 12),
        legend.text=element_text(colour ="black",size = 8),
        legend.title=element_text(colour ="black",size = 10),
        legend.key.size=unit(4,units = "mm"),
        legend.position=c(0.10,0.88),
        axis.line = element_line(size =1,colour = "black"),
        axis.ticks = element_line(size = 1,colour = "black"),
        axis.ticks.length = unit(1.5,units = "mm"),
        plot.margin=unit(x=c(top.mar,right.mar,bottom.mar,left.mar),
                         units="inches"))

# 绘图 ----------------------------------------------------------------------


dt <- read_excel('g:/脂肪酸文章/20221121/文章图片修改/数据/图2c.xlsx')
colnames(dt)
#dt$day <- factor(dt$day,levels=dt$day)
p <- ggplot(dt,aes(x=day,y=value,group=factor(group),col = group))
p1 <- p+geom_line(aes(color = group),size = 1.2)+
  geom_errorbar(
    aes(
      x = day,
      ymin = value - sd,
      ymax = value + sd,
      color = group
    ),
    # 添加误差线
    width = 0.2,
    position = position_dodge(0),
    # 设置误差线颜色,宽度等
    size = 0.8
  )+
  mytheme+
  scale_color_manual(values = brewer.pal(5,'Dark2'))+
  scale_y_continuous(limits = c(0, 7),
                     breaks = c(0.05,0.1,0.15,0.2),
                     label = c("0.05","0.1","0.15","0.2"))+
  scale_y_break(c(0.2, 0.21),scales = "free",
                ticklabels=c(0.21,0.4,0.6,0.75),
                expand=expansion(add = c(0, 0)),
                space = 1)+
  scale_y_break(c(0.75, 2),scales = "free",
                ticklabels=c(2,3,4,5,6,7),
                expand=expansion(add = c(0, 0)),
                space = 1)+
  theme(axis.text = element_text(colour = 'black',size = 20),
        text = element_text(colour = 'black',size = 20))+
  labs(x = 'Days after pollination',
       y =expression(paste("Various fatty acids(mg "^"-1",")",sep = "")),
       col = '')+
  theme(axis.line.y.right  = element_line(colour = "white"),
        axis.text.y.right  = element_text(colour = 'white'),
        axis.ticks.y.right  = element_line(colour = 'white'),
        legend.position = 'top',
        legend.text = element_text(size = 15))
p1

#8*10

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值