Search code examples
rgraphicsggplot2pointsraster

Plotting points with proporcional sizes to the values over a raster map in R


I hope someone can give me a start point to solve my problem.

I have an raster image showing the occurence prediction of a clam species. So, I have a set of coordinates, xyz like, that I would like to display over this image. I've used the function points, to display the points over the map.

Example:

myraster<-raster(nrows=250, ncols=217, xmn=540222, xmx=546732, ymn=6652656, ymx=6660156, crs=NA) # creating a raster object

set.seed(12) # placing values into raster

values(myraster) <- runif(ncell(myraster))

head(dataXYZ) # an sample of my XYZ dataset
       x       y    z
1 544500 6658000   11
2 545500 6657000    9
3 546000 6655000    2
4 544000 6655000    1
5 545000 6656500   17
6 545500 6656500   10
plot(myraster)
points(dataXYZ)

I would like to display these points with sizes proportional to the z values associated, as balloon plot in R. Also an legend.

Do Someone can give any tip to do this? An start point?

Thanks!


Solution

  • dont know what you consider a balloon plot but do you want to do this?

    x     <-  c(1, 2, 3, 4)
    y     <-  c(1, 2, 3, 4)
    size  <-  c(1, 2, 3, 4)
    
    df  <-  data.frame(x, y, size)
    
    plot(x, y, cex=size)