I have a 5 column dataframe that I'm trying to make into something like a density plot. Each row in this dataframe represents a cell in a grid that maps onto a geographic area. Let's call the dataframe columns A, B, C, D, and E. Column A contains the ID of the cell. Column B contains its longitude. Column C contains its latitude. Columns D and E contain numerical values that are associated with the grid cell.
What I'm trying to do is plot the values of Column D (or E, but let's just use D as an example) onto a geographic map (preferably a google map) using the coordinates from Column B and C such that each grid cell is accurately placed on the map and has a color that corresponds to its value in Column D. So, for example, cells with higher values of D would be red while cells with lower values of D would be grey or something
I tried using a raster to do it but I've only known about rasters since yesterday and online resources have been confusing, but that may be due to my general ignorance of how R works ( here's one source I looked at that has a picture of a similar map coloring that I am looking for). The documentation is similarly impenetrable for an amateur like myself
I tried doing:
attempt <- raster(dataframe$D, dataframe$B, dataframe$C)
but that didn't seem to help. It just gave me an error message that said
Error in (function (classes, fdef, mtable) : unable to find an inherited method for
function ‘raster’ for signature ‘"numeric"’
Should I be trying to use a raster for this? If so, how do I get this to work? If not, is there a better technique for doing something so seemingly simple?
Thanks for taking the time to read this