画柱状图,结果报错,因为y轴范围
正常图
想变小改变y轴范围,使图好看些
scale_y_continuous(expand = c(0,0),limits = c(0,a))
##改变后
scale_y_continuous(expand = c(0,0),limits = c(0.5,a))
报错
Warning message:
Removed 35 rows containing missing values (geom_bar).
使y轴无法显示坐标,而将,柱状图删除
然而函数coord_cartesian可以实现
coord_cartesian(ylim = c(0.5,a))
因两种处理方式不同
第一种为放大,只可以放大在此范围内的坐标
第二张属于截取图像坐标
代码
数据格式
data$group<-factor(data$group,levels = unique(data$group),ordered = T)
####画图
library("ggplot2")
a = max(data$average)*1.2
mi=c("#1B9E77" ,"#D95F02", "#7570B3","#E7298A")
p = ggplot(data , aes(x = group, y = average)) +
geom_bar(stat = "identity", width = 0.4,position = "dodge",colour="black",fill="#1B9E77") +
##加误差线——标准差
##geom_errorbar(aes(ymin=average - sd,ymax=average + sd),colour="black",width=0.1,size=1)+
##加多重比较结果
coord_cartesian(ylim = c(0.5,a))+
scale_y_continuous(expand = c(0,0),limits = c(0,a))+ #
geom_text(aes(label = label ,y= average + 0.001, x = group),vjust = -0.3)+
labs(x="标线类型",y="绝对误差均值",title = " ",size=10.5)+
theme_classic()+
theme(axis.text.x=element_text(angle = 80, hjust =0.5, vjust =0.5,size=10.5),
axis.text.y=element_text(size=10.5))+
theme(axis.title.x =element_text(size=10.5), axis.title.y=element_text(size=10.5))
p