在R,如何让我平行于X轴,而不是平行于Y轴?

A(巴)标绘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.

作为<强>马切伊Jończyk提到的,可能还需要增加利润

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

您需要60度如下旋转x轴标签使用主题()函数:

ggplot(...)+...+ theme(axis.text.x = element_text(angle=60, 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归因
不隶属于 StackOverflow
scroll top