如何格式化 R 中线图的 x 轴以便它可以容纳多个文本标签?
Name UP Downs
A 10 -3
B 2 -4
C 1 -1
D 4 -1
E 5 0
F 0 -1
G 6 -5
H 0 -1
I 7 -1
J 0 -1
K 0 -11
L 3 -1
M 0 -13
N 2 -1
O 0 -1
P 1 -1
Q 0 0
R 1 -1
S 0 0
T 12 -1
.....
.........
..........
(goes all the way to 2500 rows)
这是我的 R 代码的样子...
nba <- read.csv("test.csv")
plot(nba$UP, type="b", lwd=1, xaxt="n", ylim=c(-22, 22), col="red", xlab="Name",
ylab="Change", main="My plot")
axis(1, at=1:length(nba$Name), labels=nba$Name)
lines(rain$Downs, col="green", type="b", lwd=1)
该代码运行良好...但是绘制时的 x 轴显示很少的选定“名称”,而不是全部。问题是...有没有办法显示 x 轴中的所有文本(垂直且字体较小)以及当我将文件另存为图像时有没有办法...我可以放大并查看 x 轴标签。
Name UP Downs
A 10 -3
B 2 -4
C 1 -1
D 4 -1
E 5 0
F 0 -1
G 6 -5
H 0 -1
I 7 -1
J 0 -1
K 0 -11
L 3 -1
M 0 -13
N 2 -1
O 0 -1
P 1 -1
Q 0 0
R 1 -1
S 0 0
T 12 -1
.....
.........
..........
(goes all the way to 2500 rows)
Here is what my R code looks like...
nba <- read.csv("test.csv")
plot(nba$UP, type="b", lwd=1, xaxt="n", ylim=c(-22, 22), col="red", xlab="Name",
ylab="Change", main="My plot")
axis(1, at=1:length(nba$Name), labels=nba$Name)
lines(rain$Downs, col="green", type="b", lwd=1)
This code works well...but the xaxis when plotted shows few selected "Name" and not all of them. The question is ...Is there a way to show all the text in the xaxis (either vertical with smaller font) and is there a way when i save the file as an image...i can zoom in and view the xaxis labels.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您对真正想要绘制和标记的内容更有选择性,您可能会发现分析绘图会更容易。
例如,标记具有许多观测值的图的一种策略是仅标记异常值。以下示例说明了如何仅标记数据中的最高分和最低分。
创建一些示例数据并绘图。
找到 10 个最高和最低值,并使用
text
添加标签:You may find it easier to analyse your plot if you are more selective about what it is you really want to plot and label.
For example, one strategy in labelling plots with many observations is to label only the outliers. Here is an example of how you might go about labelling only the highest and lowest scores in your data.
Create some sample data and plot.
Find the 10 highest and lowest values and use
text
to add the label: