我有一个由 .csv 文件中的 3 列组成的数据集。前 2 列是地图坐标,第三列是在相应地图坐标处钻孔中发现的锌百分比。我想创建一个等高线图来显示锌浓度随距离的变化。我已经能够找到使用矩阵形式的数据的所有代码示例,而我的则在列表中。我已经尝试了几种不同的方法来绘制我在下面显示的,大多数方法都会给我错误消息,如“找不到对象 x”,我认为这与我的数据布局有关。有谁知道如何做到这一点?我在下面添加了一个类似的数据集。感谢您提前提供任何帮助。冬青
数据集:
Statsrep <- structure(list(X = c(156000L, 156010L, 156421L, 156450L, 156500L, 156700L, 158420L, 158646L, 158970L, 159050L, 159050L, 159130L, 159155L), Y = c(143630, 143980, 147260, 145000, 146000, 142800, 146700, 145207, 147170, 145200, 144800, 147815, 145890), Zn = c(2, 8, 4, 0, 3, 0, 2, 7, 12, 0, 4, 19, 0)), .Names = c("X", "Y", "Zn"), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L), class = "data.frame")
Statsrep
代码:
library(ggplot2)
Grade <- read.csv(file="filename.csv", header=TRUE, sep=",")
ggplot(Grade, aes(x$x="X", y$y="Y", z$z="Zn")) +
stat_contour()
library(lattice)
Grade <- read.csv(file="filename.csv", header=TRUE, sep=",")
levelplot(Grade ~x*y, data = Zn,
xlab = "Eastings", ylab = "Northings",
col.regions = terrain.colours)
Grade <- read.csv(file="filename.csv", header=TRUE, sep=",")
x$x <- X
y$y <- Y
z$z <- Zn
filled.contour(x$x, y$y, z$z, color = terrain.colours,
xlab = "Eastings", ylab = "Northings"),
plot.axes = {axis(1, seq(156000, 165000, by=1000)); axis(2, seq(142000, 150000, by=1000))},
key.title = title(main="Zn content\n(percent)"),
key.axes= axis(4, seq(0, 20, by = 2)))