简体   繁体   English

使用列表中的数据创建填充等高线图

[英]Creating a filled contour plot using data in lists

I have a data set that consists of 3 columns in a .csv file. 我有一个数据集,由.csv文件中的3列组成。 The first 2 columns are map co-ordinates and the third is the percentage of zinc found in a borehole at the corresponding map co-ordinates. 前两列是地图坐标,第三列是相应地图坐标中钻孔中发现的锌的百分比。 I would like to create a contour map to show the Zn concentration changes with distance. 我想创建一个等高线图来显示Zn浓度随距离的变化。 All of the examples of code I have been able to find use data in the form of a matrix, whereas mine are in lists. 代码的所有示例我都能够以矩阵的形式找到使用数据,而我的列表则是。 I have tried several different ways of plotting this which I have shown underneath, the majority of methods give me error messages along the lines of "object x not found" which I think is to do with the layout of my data. 我已经尝试了几种不同的方法来绘制我在下面显示的方法,大多数方法都给出了“对象x未找到”的错误消息,我认为这与我的数据布局有关。 Does anyone know how to do this? 有谁知道如何做到这一点? I have added a similar data set to mine below. 我在下面添加了一个类似的数据集。 Thanks for any help in advance. 在此先感谢您的帮助。 Holly 冬青

Data set: 数据集:

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

Code: 码:

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)))

Working with ggplot2, you can create a contour plot with your example data set using: 使用ggplot2,您可以使用以下示例创建包含示例数据集的等高线图:

ggplot(Statsrep, aes(x=X, y=Y, z=Zn)) + 
    geom_density2d()

to give

在此输入图像描述

You had a couple of problems with the ggplot2 code. 你有一些ggplot2代码的问题。 In particular, where you set the aesthetics you had: 特别是,你设置美学的地方:

aes(x$x="X", y$y="Y", z$z="Zn")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM