简体   繁体   English

在R中隔开x轴标签

[英]Spacing out x-axis labels in R

I'm with MLB salaries and I'm trying to plot a frequency distribution to visualize the skewness of the figure. 我拥有美国职业棒球大联盟的薪水,并且试图绘制频率分布以形象化图形的偏斜度。 I'm having trouble making the x-axis labels of my histogram. 我在制作直方图的x轴标签时遇到问题。 Btw, I got my MLB salary data from here . 顺便说一句,我从这里获得了美国职业棒球大联盟的薪水数据。

Here is how I generated my distribution: 这是我生成分配的方式:

hist(data, breaks = 33, axes = F)

Given my salaries range from 0 to $35 Million, I generated my labels like this - 给定我的薪水范围从0到3500万美元,我生成了这样的标签-

x.axis <- pretty(seq(0,35000000, by = 10000000))/10000000

x.axis
>[1] 0.0 0.5 1.0 1.5 2.0 2.5 3.0

Using the axis() function only plots the first 8 labels. 使用axis()函数仅绘制前8个标签。

axis(1, at = y, labels = paste(y, "M", sep =""))

I realize this is because as length(x.axis) = 8 . 我意识到这是因为length(x.axis) = 8

Is there any way of spacing out the ticks on my x-axis? 有什么办法可以隔开我的x轴上的刻度线?

Thanks in advance! 提前致谢!

Figured it out! 弄清楚了!

pts <- pretty(data/10000000)
a <- (seq(0,35000000, by = 5000000))

axis(1, at = a, labels = paste(pts, "M", sep =""))

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

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