r - 如何调整图表中的轴标签?

标签 r plot cluster-analysis

我不明白为什么我不能调整我的 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))

这就是我所拥有的:

my graph

最佳答案

我会使用 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))

enter image description here


数据:

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

关于r - 如何调整图表中的轴标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65361797/

相关文章:

java - MOA 的 StreamKM 聚类不返回任何结果

r - ggplot2:彩色垂直线

c++ - rcpp 函数中的清理时间较长

python - 如何在Python中关闭绘图窗口后设置绘图标题

colors - gnuplot - 如何获得与 3d 绘图具有相同级别颜色的等高线

r - 如何在R中创建聚类图?

cluster-analysis - 选择和实现聚类方法 : DBSCAN something else?

R问题。绘制响应时出现无法解释的空因子组合

r - 使用 TraMineR : How are event sequences without any transition represented? 的平行坐标图 (seqpcplot)

plot - Julia :当我有情节时如何找到最佳拟合曲线/方程?