我正在尝试基于经度/纬度格式的数据创建透视图。
纬度和经度正确地绘制,但背景是奇怪的黑色。我该怎么改变呢
persp(lga_crop_05, expand =0.5, phi = 35, col= "lightblue", ticktype = "detailed")
这是我创建情节的代码。 lga_crop_05
是我的光栅图,其中包含我上面附加的情节的纬度/经度/值。
我将不胜感激任何帮助。 感谢
答案 0 :(得分:4)
What has gone wrong?
Nothing wrong with the code; but with our eyes. Try the following code:
## a function to produce a perspective plot
## "n" controls how refined your grid is
foo <- function(n) {
x <- seq(-1.95, 1.95, length = n)
y <- seq(-1.95, 1.95, length = n)
z <- outer(x, y, function(a, b) a*b^2)
persp(x, y, z, col = "lightblue")
}
If we have a 10 * 10 grid, the colour looks perfect.
foo(10)
If we have a 100 * 100 grid, the colour still looks OK.
foo(100)
Now, if we have extremely refined data, for example, on a 1000 * 1000 grid. Everything will just look like black.
foo(1000)
Note that you have a raster. I would suspect that your data are simply too refined. Have you checked how many cells you have in your lga_crop_05
?
How to get around?
Set border = NA
. Try modified function:
foo1 <- function(n) {
x <- seq(-1.95, 1.95, length = n)
y <- seq(-1.95, 1.95, length = n)
z <- outer(x, y, function(a, b) a*b^2)
persp(x, y, z, col = "lightblue", border = NA)
}
答案 1 :(得分:4)
我使用了Mr.Li的示例数据,谢谢。我想这就是你想要的。
# I changed x and y length irregular.
x <- seq(-1.95, 1.95, length = 500)
y <- seq(-1.95, 1.95, length = 200)
z <- outer(x, y, function(a, b) a*b^2)
# make persp.object and draw it
surf <- persp(x, y, z, col = "lightblue", border = NA, theta = -30)
# draw lines parallel to x axis. seq(...) depends on your data's length(y)
for(i in seq(10, 190, length=10)) lines(trans3d(x, y[i], z[,i], pmat = surf), col = "red")
# draw lines parallel to y axis. seq(...) depends on your data's length(x)
for(i in seq(25, 475, length=10)) lines(trans3d(x[i], y, z[i,], pmat = surf), col = "blue")