使用列表中的数据创建填充轮廓图 [英] Creating a filled contour plot using data in lists

查看:225
本文介绍了使用列表中的数据创建填充轮廓图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由.csv文件中的3列组成的数据集。前两列是地图坐标,第三列是相应地图坐标中钻孔中锌的百分比。我想创建一个等值线图来显示Zn浓度随距离的变化。所有代码示例都能够以矩阵的形式找到使用数据,而我的代码则在列表中。我已经尝试了几种不同的绘制方式,我已经在下面展示了这些方法,大多数方法都会给我提供错误信息,这些信息沿着对象x未找到的方向发展,我认为这与我的数据布局有关。有谁知道如何做到这一点?我在下面添加了一个类似的数据集。感谢您提前提供任何帮助。
Holly

数据集:

  Statsrep< - 结构(列表(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)),名称= 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)
等级< - 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 =文件name.csv,header = TRUE,sep =,)
x $ x < - X
y $ y < - Y
z $ z < - Zn
填充.contour(x $ x,y $ y,z $ z,color = terrain.colours,
xlab =Eastings,ylab =Northings),
plot.axes = {axis(1 ,seq(156000,165000,by = 1000));轴(2,seq(142000,150000,by = 1000))},
key.title = title(main =Zn content\\\
(percent)),
key.axes = axis (4,seq(0,20,by = 2)))


解决方案

使用ggplot2,您可以使用以下示例数据集创建轮廓图:

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


p>

您在 ggplot2 代码中遇到了一些问题。特别是,如果您设置了美学设计:

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


I have a data set that consists of 3 columns in a .csv file. 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. 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. 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:

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

to give

You had a couple of problems with the ggplot2 code. In particular, where you set the aesthetics you had:

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

这篇关于使用列表中的数据创建填充轮廓图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆