R 中的旋转轴标签

发布于 2024-08-12 15:09:13 字数 40 浏览 2 评论 0原文

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

How do I make a (bar) plot's y axis labels parallel to the X axis instead of parallel to the Y axis?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

七禾 2024-08-19 15:09:13

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

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

output

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

Not sure if this is what you mean, but try setting las=1. Here's an example:

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

output

That represents the style of axis labels. (0=parallel, 1=all horizontal, 2=all perpendicular to axis, 3=all vertical)

假装爱人 2024-08-19 15:09:13

使用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.

Use par(las=1).

See ?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.
月隐月明月朦胧 2024-08-19 15:09:13

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

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

As Maciej Jończyk mentioned, you may also need to increase margins

par(las=2)
par(mar=c(8,8,1,1)) # adjust as needed
plot(...)
苄①跕圉湢 2024-08-19 15:09:13

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

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

You need to use theme() function as follows rotating x-axis labels by 90 degrees:

ggplot(...)+...+ theme(axis.text.x = element_text(angle=90, hjust=1))
夢归不見 2024-08-19 15:09:13

首先,为图表创建数据

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()

输出:

在此处输入图像描述

First, create the data for the chart

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

Second, give the name for a chart file

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

Third, Plot the bar chart

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)

Finally, save the file

dev.off()

Output:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文