如何在X轴图中不忽略NA值? [R]

时间:2018-09-05 14:20:24

标签: r

我正在尝试绘制将三个图形合并在一起的图。 (请参见下面的图)

所有这三个值的x值都在0.0到1.0之间变化。 但是,只有其值实际更接近最终x值(1.0)的图才具有整个x轴范围。

查看函数axis(),我看到“省略了非限定(无限,NaN或NA)值”,因此有意义的是,没有1.0左右值的图将没有等效值x轴。

首先,我认为可能是因为它们的大小,但是即使从绘图中减少了cex,x轴仍保持不变。

如何解决这种情况?我真的希望所有三个图都具有整个x轴,且在0.0-1.0之间变化。

我正在使用的脚本是基本的axis()函数,例如: 轴(1,c(0.0,0.2,0.4,0.6,0.8,1.0))

整个代码(有点混乱,抱歉):

t = c(0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 320, 340, 360)
p = c(0.0, 0.2, 0.4, 0.6, 0.8, 1.0)
par(mfrow=c(1,3))
par(mar= c(5.1, 5, 3, 0))
plot (Pertinencia_Cluster_1, prof, axes = FALSE, type = 'n', xlab = '', 
      ylab = 'Profundidade (m)', cex.main = 0.8)
# rect(0, 153, 4, 190, col = '#fffae6', border = "#fffae6")
# rect(0, 203, 4, 248, col = '#fffae6', border = "#fffae6")
axis(1, p)
axis(2, t)
grid()
lines(Pertinencia_Cluster_1, prof, col = '#cc0000', pch = 16, cex = 0.8)
points(Pertinencia_Cluster_1, prof, col = '#cc0000', pch = 16, cex = 0.8)
legend(0.12, -25, xpd = TRUE, legend = "Pertinência Cluster 1", pch = 16, col = "#cc0000", cex = 1.0)


par(mar= c(5.1, 2.5, 3, 2.5))
plot (Pertinencia_Cluster_2, prof, col = "#008B8B", pch = 17, cex = 1.0, axes = FALSE, xlab = '', 
      ylab = '', cex.main = 0.8, type = 'n')
# rect(0, 115, 4, 153, col = '#fffae6', border = "#fffae6")
# rect(0, 185, 4, 215, col = '#fffae6', border = "#fffae6")
axis(1, p)
grid()
lines(Pertinencia_Cluster_2, prof, col = '#009900', pch = 16, cex = 0.8)
points(Pertinencia_Cluster_2, prof, col = '#009900', pch = 16, cex = 0.8)
legend(0.12, -25, xpd = TRUE, legend = "Pertinência Cluster 2", pch = 16, col = "#009900", cex = 1.0)


par(mar= c(5.1, 0, 3, 5))
plot (Pertinencia_Cluster_3, prof, col = "#008B8B", pch = 17, cex = 1.0, axes = FALSE, xlab = '', 
      ylab = '', cex.main = 0.8, type = 'n')
# rect(0, 0, 4, 87, col = '#fffae6', border = "#fffae6")
axis(1, p)
grid()
lines(Pertinencia_Cluster_3, prof, col = '#0099ff', pch = 16, cex = 0.8)
points(Pertinencia_Cluster_3, prof, col = '#0099ff', pch = 16, cex = 0.8)
legend(0.12, -25, xpd = TRUE, legend = "Pertinência Cluster 3", pch = 16, col = "#0099ff", cex = 1.0)

title('Clay Minerals (Smectite, Palygorskite, Illite, Chlorite & Kaolinite)', outer = T, line = -2)

My plot

1 个答案:

答案 0 :(得分:0)

在每个xlim=c(0,1)命令中添加plot()