0

I'm trying to plot a continuous variable on space. I think that I should estimate its intensity also in other points of space. I saw this example that gets the same result that I need.

library("MASS")
library("ggplot2")
library(reshape2) 

DB<-melt(volcano)
ggplot(DB, aes(x=Var1, y=Var2, fill=value)) + geom_point()
ggplot(DB, aes(x=Var1, y=Var2, fill=value)) +geom_tile()

enter image description here

enter image description here

So I used the same code on my data:

step<-NULL
step$lat<-c(45.46903, 45.46903 ,45.47195, 45.46902 ,45.46610, 45.45884, 45.47488 ,45.47196, 45.46613 ,45.46320, 45.46318)
step$long<- c(9.192541, 9.195815, 9.195825, 9.199089, 9.199079 ,9.174503 ,9.186013, 9.189277 , 9.182710, 9.189248, 9.199069)
step$z<- c(12153.061 ,13832.401, 17153.554 , 9823.469, 19091.823, 31023.074, 15836.885,11454.056 ,12839.104, 23426.680 ,13096.105)

step<-as.data.frame(step)


ggplot(step,aes(x=long,y=lat,fill=z))+geom_point()
ggplot(step,aes(x=long,y=lat,fill=z))+geom_tile()

enter image description here

enter image description here

My final plot is empty! Maybe the problem is that I have not enough points.

dax90
  • 1,088
  • 14
  • 29
  • I think you're right about the points. If you look at the result of `melt(volcano)`, you'll see that it has a data point for every point in the whole-number grid that gets plotted. – ulfelder Jul 15 '15 at 09:52
  • 1
    @ulfelder Easier to see it with the first plot. –  Jul 15 '15 at 10:00
  • 1
    Have your tried `ggplot(step,aes(x=long,y=lat))+ stat_density2d(aes( fill=..level..), geom='polygon') + geom_point() ` (is that the sort of thing you are after?) – Tom Liptrot Jul 15 '15 at 10:59
  • alternatively this: `ggplot(step,aes(x=long,y=lat))+ stat_density2d(geom="tile", aes(fill = ..density..), contour = FALSE)`. This page: http://docs.ggplot2.org/0.9.3/stat_density2d.html should be helpful – Chris Jul 15 '15 at 19:33
  • That code doesn't plot the intensity of the z variable value. – dax90 Jul 16 '15 at 09:10
  • I think your question is not about ggplot2. It is about "surface fitting". You could try the [rsm](https://cran.r-project.org/web/packages/rsm/vignettes/rsm-plots.pdf) package. – peterchen932 Jul 17 '15 at 11:15
  • This is an interesting package. Anyway this is useful to plot the prediction of a model estimated. I need only to give a visualization of the z variable. My x and y are latitude and longitude. – dax90 Jul 17 '15 at 16:28
  • I thought that your data is not enough to plot a surface like "volcano" example, so you need "surface fitting". If you just want to visualize "Z", you could plot 3D by [scatterplot3d](https://cran.r-project.org/web/packages/scatterplot3d/scatterplot3d.pdf) package, and example code is `scatterplot3d(step$long, step$lat, step$z,type="h",highlight.3d=T,lab.z=1,angle=15)` or by [rgl](https://cran.r-project.org/web/packages/rgl/rgl.pdf) package, and example code is `plot3d(step$long, step$lat, step$z, type="h", lwd=3)`. – peterchen932 Jul 18 '15 at 06:47
  • I used a method (inside the mgcv package) to estimate the intensity in the space of the variable. I don't think that my method is the best one so I keep this question open. Anyway now I have more points in the space. Enought to use the geom_tile. But I have anothe problem: http://stackoverflow.com/questions/31505880/plot-the-intensity-of-a-continuous-with-geom-tile-in-ggplot – dax90 Jul 19 '15 at 21:02

0 Answers0