【问题标题】:How to adjust axis labels in a graph?如何调整图表中的轴标签?
【发布时间】:2021-03-29 09:19:33
【问题描述】:

我不明白为什么我不能调整我的 x 轴标签。

我一直在尝试使用以下代码,但效果不佳。

x1 <- c(80, 5, 8)
x2 <- c(70, 0, 25)

plot(x1, type="o",col="red", xlab="cluster", ylab="Percent", 
     main="GDP vs Population", pch =17)
text(seq(1, 10, by=1), par("usr")[3] - 0.2, 
     labels=c("Cluster 1", "Cluster 2", "Cluster 3"), xpd=TRUE)
lines(x2, type="o", col="blue", pch =19)
legend("topright", 
       legend=c("GDP", "Population"), 
       col=c("red", "blue"), 
       pch=c(17,19), 
       bty="n", 
       pt.cex=1, 
       cex=1, 
       text.col="black", 
       horiz=F , 
       inset=c(0.1, 0.1))

这就是我所拥有的:

【问题讨论】:

    标签: r plot cluster-analysis


    【解决方案1】:

    我会使用mtext。首先,使用xaxt="n" 关闭自动 x 轴。其次,在1:3 处重建它,使用axis 作为刻度线,使用mtext 作为标签。

    plot(x1,type="o",col="red", xlab="cluster", ylab="Percent", 
         main="GDP vs Population", pch =17, xaxt="n")
    lines(x2, type="o", col="blue", pch =19)
    axis(side=1, at=1:3, labels=paste("cluster", 1:3))
    legend("topright", 
           legend=c("GDP", "Population"), 
           col=c("red", "blue"), 
           pch=c(17,19), 
           bty="n", 
           pt.cex=1, 
           cex=1, 
           text.col="black", 
           horiz=F , 
           inset=c(0.1, 0.1))
    


    数据:

    x1 <- c(80, 5, 8)
    x2 <- c(70, 0, 25)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-26
      • 2020-06-23
      • 2014-07-22
      • 2021-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多