Color gradient for height data in XYZ plot with R and grid

I have an XYZ data group, where X and Y are the coordinates and Z is the height (LiDAR points). I am trying to build this point cloud with a gradient based on the Z value.

Here is what I still have:

# Read the CSV file with the LiDAR point cloud (which was conveniently converted to CSV)
myData <- read.csv("./52I212_plot10.las.csv")
# We don't need all attributes, let keep only X, Y and Z.
myData <- subset(myData, select=c(X,Y,Z))
# We want a normalized version of Z (between 0 and 1)
myData$normalZ <- (myData$Z-min(myData$Z))/(max(myData$Z)-min(myData$Z))
str(myData)

With this I am trying to create a graph using

library(lattice)
ramp <- colorRampPalette(c("lightblue", "red"))
cloud(myData$Z ~ myData$X + myData$Y, xlab="X", ylab="Y", zlab="Z",pch=20,
  col.point=ramp(10)[myData$normalZ*10]) 

I expected Z values ​​to have one of ten possible colors between lightblue and red. XYZ plot, different colors

When I change the plot command to

cloud(myData$Z ~ myData$X + myData$Y, xlab="X", ylab="Y", zlab="Z",pch=20,
  col.point=gray(myData$normalZ))

I get what is much closer to what I need:

Much better!

I suspect that I am doing something wrong on the color ramp, but I cannot understand that.

early

Raphael

EDIT

This question: How to combine vector values ​​with colors from the color ramp in R? They helped me a lot, but I still don’t understand what I did wrong. This code works:

myData$normalZ <- (myData$Z-min(myData$Z))/(max(myData$Z)-min(myData$Z))
ramp <- colorRamp(c("lightblue", "red"))
cols <- ramp(myData$normalZ)
cloud(myData$Z ~ myData$X + myData$Y, xlab="X", ylab="Y", zlab="Z",pch=20,
      col.point=rgb(cols,maxColorValue = 256))

Aha!

, , - , .

+4
2

, , 0 . normalZ 0 1, 10 * normalZ 0 10. [, . ( , ?"[": " [ i] , as.integer(, , )".

0 ( - 1) , , :

ramp(10)[c(0, 0.4, 0.8, 1.2, 1.6)]
# [1] "#ACD8E5" "#ACD8E5"

. , , ,

col.point = ramp(10)[ceiling(myData$normalZ * 10)]
+2

z- .

library(lattice)

N <- 500
myData <- data.frame(X = runif(N,0,30),
                     Y = runif(N,0,30),
                     Z = runif(N,0,300))

myData$normalZ <- (myData$Z-min(myData$Z))/(max(myData$Z)-min(myData$Z))

ramp <- colorRampPalette(c("lightblue", "red"))

cloud(myData$Z ~ myData$X + myData$Y, xlab="X", ylab="Y", zlab="Z",pch=20,
      col.point=ramp(10)[myData$normalZ*10])

myData$normalZ*10 Z- (0,1) (0,10). ( .) (10) 10 ( 11) , R 1 0, Z NULL. .

: Z:

enter image description here

,

cloud(myData$Z ~ myData$X + myData$Y, xlab="X", ylab="Y", zlab="Z",pch=20,
      col.point=ramp(10)[myData$normalZ*9+1])

, :

enter image description here

+2

Source: https://habr.com/ru/post/1607565/


All Articles