title: 2D surface plotting R
body: <p>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 :(</p>
  
  <p>I have X and Y coordinates within space (each X,Y pair refers to one point) for example:</p>
  
  <pre><code>x   y
  10  15
  11  11
  8   11
  15  14
  15  8
  13  11
  50  29
  29  30
  90  40
  55  39
  </code></pre>
  
  <p>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). </p>
  
  <p>The ideal solution looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/5gMr1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5gMr1.png" alt="enter image description here"></a></p>
  
  <p>I’ve attempted to use this -  <a href="https://cran.r-project.org/web/packages/HSAUR/vignettes/Ch_density_estimation.pdf" rel="nofollow noreferrer">https://cran.r-project.org/web/packages/HSAUR/vignettes/Ch_density_estimation.pdf</a> (this is where I found the image above). But unfortunately I can’t get the examples to work – the library with data is unavailable! </p>
  
  <p>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.</p>
  
  <p>I really hope someone can help me!</p>
  
  <p>EDIT:
  So far I've tried to follow the instructions in the file above, which meant using Gaussian function to estimate the peaks. </p>
  
  <pre><code>test &lt;- read.csv("test1.csv", header = TRUE)
  gauss &lt;- function(x) 1/sqrt(2*pi) * exp(-(x^2)/2)
  n &lt;- 100
  h &lt;- 10
  xgrid &lt;- seq(from = 0, to = 1280, by = 16)
  bumps &lt;- sapply(test$x, function(a) gauss((xgrid - a)/h)/(n * h))
  persp(bumps, theta = 60, axes = TRUE, box = TRUE)
  </code></pre>