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
ggplot:截断坐标轴的折线图(带误差线)
最新推荐文章于 2024-08-20 20:47:48 发布