繁体   English   中英

R中的旋转轴标签

[英]rotating axis labels in R

在 R 中,如何使(条形)图的 y 轴标签平行于 X 轴而不是平行于 Y 轴?

不确定这是否是您的意思,但请尝试设置las=1 下面是一个例子:

require(grDevices)
tN <- table(Ni <- stats::rpois(100, lambda=5))
r <- barplot(tN, col=rainbow(20), las=1)

输出

那代表轴标签的样式。 (0=平行,1=全部水平,2=全部垂直于轴,3=全部垂直)

使用par(las=1)

?par

las
numeric in {0,1,2,3}; the style of axis labels.
0: always parallel to the axis [default],
1: always horizontal,
2: always perpendicular to the axis,
3: always vertical.

正如Maciej Jończyk提到的,您可能还需要提高利润率

par(las=2)
par(mar=c(8,8,1,1)) # adjust as needed
plot(...)

您需要使用 theme() 函数,如下所示将 x 轴标签旋转 90 度:

ggplot(...)+...+ theme(axis.text.x = element_text(angle=90, hjust=1))

首先,为图表创建数据

H <- c(1.964138757, 1.729143013,    1.713273714,    1.706771799,    1.67977205)
M <- c("SP105", "SP30", "SP244", "SP31",    "SP147")

其次,给出图表文件的名称

png(file = "Bargraph.jpeg", width = 500, height = 300)

三、绘制条形图

barplot(H,names.arg=M,ylab="Degree ", col= rainbow(5), las=2, border = 0, cex.lab=1, cex.axis=1, font=1,col.axis="black")
title(xlab="Service Providers", line=4, cex.lab=1)

最后,保存文件

dev.off()

输出:

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM