I’m attempting to create a 3D surface plot in R – I’ve read a number of other questions, but can’t find the solution for this :(
I have X and Y coordinates within space (each X,Y pair refers to one point) for example:
x y
10 15
11 11
8 11
15 14
15 8
13 11
50 29
29 30
90 40
55 39
I would to plot these points as a surface plot, so that where there are more points in close vicinity, the density of the plot is higher (e.g. its obvious there are many points close to (10,10) and only one point at (90,40).
The ideal solution looks like this:
I’ve attempted to use this - https://cran.r-project.org/web/packages/HSAUR/vignettes/Ch_density_estimation.pdf (this is where I found the image above). But unfortunately I can’t get the examples to work – the library with data is unavailable!
The idea is to have this visualisation to be compared to the surface image, so I need x and y coordinates (0,0) to start in one place (as on the image, both logs start in one corner). I also need the axis to be unequal, with x axis going from 0 to 100 and y axis going from 0 to 50, so that original coordinates aren't distorted and the visualisation displays the data proportionately to the surface.
I really hope someone can help me!
EDIT: So far I've tried to follow the instructions in the file above, which meant using Gaussian function to estimate the peaks.
test <- read.csv("test1.csv", header = TRUE)
gauss <- function(x) 1/sqrt(2*pi) * exp(-(x^2)/2)
n <- 100
h <- 10
xgrid <- seq(from = 0, to = 1280, by = 16)
bumps <- sapply(test$x, function(a) gauss((xgrid - a)/h)/(n * h))
persp(bumps, theta = 60, axes = TRUE, box = TRUE)