2016-04-29 88 views
0

所以我和我的同事在R(使用管道:Package dplyr,magrittr)中制作了我的数据矩阵,并将其绘制在filled.contour图中。但由于某种原因,它不会绘制我的最后两点。R:填充轮廓图不会绘制所有矩阵

有没有人有解决这个问题?

这是我dput我的数据集/矩阵:

structure(list(AvgDepth = c(5L, 5L, 15L, 5L, 15L, 25L, 5L, 15L, 
25L, 35L, 5L, 15L, 25L, 35L, 5L, 15L, 25L, 35L, 45L, 5L, 15L, 
25L, 35L, 45L, 55L, 5L, 15L, 25L, 35L, 45L, 55L, 65L, 5L, 15L, 
25L, 35L, 45L, 55L, 65L, 75L, 5L, 15L, 25L, 35L, 45L, 55L, 65L, 
75L, 85L, 95L), AvgMaxDepth = c(5L, 15L, 15L, 25L, 25L, 25L, 
35L, 35L, 35L, 35L, 45L, 45L, 45L, 45L, 55L, 55L, 55L, 55L, 55L, 
65L, 65L, 65L, 65L, 65L, 65L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 
85L, 85L, 85L, 85L, 85L, 85L, 85L, 85L, 95L, 95L, 95L, 95L, 95L, 
95L, 95L, 95L, 95L, 95L), MiddleOldG = c(-0.010339548, 
-0.019087115, -0.013710817, -0.018843724, -0.016954714, -0.009270159, 
-0.021369483, -0.020470118, -0.020793118, -0.038538718, -0.014960888, 
-0.010406261, -0.014440231, -0.018794958, -0.020203279, -0.015599607, 
-0.017050242, -0.024199387, -0.025290379, -0.026409047, -0.023564188, 
-0.027233605, -0.031364833, -0.033557383, -0.036140136, -0.022472455, 
-0.011018529, -0.01468673, -0.022262797, -0.027657312, -0.026680228, 
-0.02738715, -0.025351831, -0.026051226, -0.021691668, -0.025787225, 
-0.018350888, -0.019350486, -0.018076008, -0.011645933, -0.005070788, 
-0.006843451, -0.001764863, -0.001371702, -0.002248032, -0.002476992, 
0.00325166, 0.004070139, 0.033053363, 0.022264692), x = c(1, 
1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5, 1, 2, 3, 
4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 
4, 5, 6, 7, 8, 9, 10), y = c(1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 
5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 
9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 
)), class = "data.frame", .Names = c("AvgDepth", "AvgMaxDepth", 
"MiddleOldG", "x", "y"), row.names = c(NA, 
-50L)) 

这里的矩阵是什么样子:

http://i.stack.imgur.com/x6ngn.png

下面是代码

library(colorspace) 
library(dplyr) 
library(magrittr) 

Descent<-read.csv(file.choose()) 

attach(Descent) 

summary(Descent) 

Descent %<>% mutate(x = (AvgDepth + 5)/10, y = (AvgMaxDepth + 5)/10) 

z = matrix(NA, ncol = 10, nrow = 10) 

z.middle = Descent %>% select(x, y, MiddleOldG) 

for (i in 1:nrow(z.middle)) z[z.middle[i,1],z.middle[i,2]] = z.middle[i,3] 

filled.contour(x = seq(5, 95, by = 10), y = seq(5, 95, by = 10), z, color.palette=diverge_hsv, xlab="Depth (m)", ylab="Maximum Depth (m)", levels = pretty(c(-0.04,0.04),24)) 

但它不会绘制9,10和10,10数据点ts在矩阵中

它们应该在图的右上角,但它们不是。

Filled.Contour

为什么它不绘制的最后两点的任何想法?

这里是数据集:https://docs.google.com/spreadsheets/d/13BJQ9-EXr2wu5tZNqXSzdbg_cLUjVw65W7yAAwydf_8/edit?usp=sharing

由于

+0

如果你看看'填补。轮廓“,所以你应该找出失败原因的描述。 –

+0

@ 42-我一直在寻找,没有结果 – LearningTheMacros

+0

我误解了这个问题,因为你说要绘制filled.contour内的点。相反,你没有注意到的原因是人们不愿意在没有易于剪切和粘贴的数据的情况下再现你的问题。没有人可以导入该图像。学习将dput(Descent)的结果发布为现有问题的编辑。 –

回答

0

filled.contour函数需要4个点,以形成填充区域。如果你在第9列组相邻的点,你再拿到在右上角对应矩阵的右下“角”合适的颜色:

z[9:10,9] <- 0 
filled.contour(x = seq(5, 95, by = 10), y = seq(5, 95, by = 10), z, 
       color.palette=diverge_hsv, xlab="Depth (m)", ylab="Maximum Depth (m)", 
       levels = pretty(c(-0.04,0.04),24)) 

enter image description here