【R语言】柱状图边框加粗
一提到画柱状图
大家第一想到的
是不是barplot函数呢?
但是barplot画出来是酱紫的
柱状图的边框比较细
而且全网搜了很久
都找不到加粗边框的方法
今天下午我灵机一动
我用线来画柱状图
因为线可以加粗
一条一条地把柱状图勾勒出来
通过这些小问题
也帮助我们进一步熟悉R语言
代码
rm(list=ls()) #清除环境
par(mar=c(3,5,1,1))
D1 <- c(0.37,3.61) #画柱状图用到的数据
D2 <- c(0.61,3.03) #画误差棒用到的数据
rnames <- c("N","T") #排名
cnames <- c("") #列名
mymatrix <- matrix(D1,nrow=2,ncol=1,byrow=T,#按列填充
dimnames=list(rnames,cnames))
mymatrix
barplot(mymatrix,axes=F,col="white",border = c("#57afdf","#e1291d"),
ylim = c(-0.1,4),xlim = c(0.9,4), beside = T, space = 1,
xlab = "", ylab = "Staining intensity",cex.lab=1.3, font.lab="2")
plot(mymatrix,axes=F,col="white",ylim = c(-0.001,4),xlim = c(0.9,3.4),
xlab = "", ylab = "Staining intensity",cex.lab=1.3, font.lab="2") +
arrows(x0=1.5, y0=0.37, x1=1.5, y1=0.41, angle=90,col="#57afdf",
lwd = 3, length = 0.15)+
arrows(x0=2.8, y0=3.61, x1=2.8, y1=3.80, angle=90, col="#e1291d",
lwd = 3, length = 0.15)+
arrows(x0=1, y0=0, x1=1, y1=0.37, angle=90,col="#57afdf",
lwd = 3, length = 0)+
arrows(x0=1, y0=0.37, x1=2, y1=0.37, angle=0,col="#57afdf",
lwd = 3, length = 0)+
arrows(x0=2, y0=0, x1=2, y1=0.37, angle=90,col="#57afdf",
lwd = 3, length = 0)+
arrows(x0=1, y0=0, x1=2, y1=0, angle=0,col="#57afdf",
lwd = 3, length = 0)+
arrows(x0=2.3, y0=0, x1=2.3, y1=3.61, angle=90,col="#e1291d",
lwd = 3, length = 0)+
arrows(x0=2.3, y0=3.61, x1=3.3, y1=3.61, angle=0,col="#e1291d",
lwd = 3, length = 0)+
arrows(x0=3.3, y0=0, x1=3.3, y1=3.61, angle=90,col="#e1291d",
lwd = 3, length = 0)+
arrows(x0=2.3, y0=0, x1=3.3, y1=0, angle=0,col="#e1291d",
lwd = 3, length = 0)+
axis(2,at=c(0,1,2,3,4), #2表示设置左坐标轴(y轴)
label=c("0","1","2","3","4"),lwd=3,
lwd.ticks = 3,
font.axis=2, #坐标标签“1”为正常,“2”为加粗,“3”为斜体
cex.axis=1.3)+ #坐标标签大小,默认为1
axis(1,at=c(1,4),label=c("",""),lwd = 3,lwd.tick = NA, #1表示设置下方坐标轴(x轴)
font.axis=2) +
axis(1,at=c(1.5,3.5),label=c("N","T"),lwd = 3,lwd.ticks = 3, #1表示设置下方坐标轴(x轴)
font.axis=2,cex.axis=1.3)
往期文章:
趋势线
最后悄悄说一句
也可以用AI把框加粗
简单又快速~
不过跟着今天的文章练一练
也能帮助大家更好地理解R语言
多练才能融会贯通呀~
如果这篇文章对您有用~
求关注、在看、转发~