【问题标题】:Can't get rid of the original x-axis tick labels无法摆脱原来的 x 轴刻度标签
【发布时间】:2018-10-06 20:43:15
【问题描述】:

所以当我制作直方图时,x 轴刻度标签默认为科学记数法(我不想要),所以我想将它们更改为数据的四分位数。当我运行以下代码时,会添加新标签,但旧标签仍在下方。这是不可读的。如何删除原始标签并替换它们?

marks = c(171959, 429897, 509702, 581455, 862469)  
hist(net.worth$`Net Worth`, main="Net Worth", xlab="Net Worth", ylab="Customers", col="light blue")  
axis(1, at=marks, labels=marks)

【问题讨论】:

  • options(scipen = 10) 解决了我最初的问题,但我仍然想知道是什么导致了未来的这种重叠

标签: r plot histogram


【解决方案1】:

您会得到重复的 x 轴标签,因为您将它们绘制了两次:第一次使用 hist() 函数将它们与直方图一起绘制。第二次通过调用axis() 添加它们。

您可以通过添加xaxt='n' 参数来禁止在hist 内绘制原始x 轴标签:

marks = c(171959, 429897, 509702, 581455, 862469)  
hist(net.worth$`Net Worth`, main="Net Worth", xlab="Net Worth", xaxt='n', ylab="Customers", col="light blue")  
axis(1, at=marks, labels=marks)

【讨论】:

    猜你喜欢
    • 2014-09-27
    • 2011-03-28
    • 1970-01-01
    • 2012-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多