I want to make a bathymetry map using ggplot2. I converted a raster file to a data frame, clopped and converted it to a dataframe:
library(raster)
##Import a raster file
Bathymetry_dat <- raster("w001000.adf")
##Clop the raster file
Bathy_clopped <- crop(Bathymetry_dat, extent(84.11236, 108.4594, -4.046979, 24.09534))
##Convert it to a dataframe
datframe_bathy<-as.data.frame(Bathy_clopped, xy = TRUE)
Then, I checked values (i.e. depth in m) in the dataframe:
> summary(datframe_bathy)
x y w001000_COUNT
Min. : 84.11 Min. :-4.046 Min. : 9945
1st Qu.: 90.20 1st Qu.: 2.987 1st Qu.: 81618
Median : 96.28 Median :10.021 Median : 168447
Mean : 96.28 Mean :10.021 Mean : 210212
3rd Qu.:102.37 3rd Qu.:17.054 3rd Qu.: 336718
Max. :108.45 Max. :24.087 Max. :1205362
NA's :3449125
Depth (m) values are supposed to be negative and should't be this large. Then, I checked the bathymetry file imported in R.
> Bathy_clopped
class : RasterLayer
dimensions : 3377, 2922, 9867594 (nrow, ncol, ncell)
resolution : 0.008333333, 0.008333333 (x, y)
extent : 84.10833, 108.4583, -4.05, 24.09167 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
data source : in memory
names : w001000
values : -6138, -1 (min, max)
attributes :
ID COUNT
from: -11584 1
to : -1 676804
There are two attributes: ID and COUNT. I suppose ID is depth (m) and don't know what COUNT is. And it is weird that COUNT ranges from 1 to 676804 and but summary() shows values from 9945 to 1205362.
So my question is how can I convert a raster file to a dataframe that contains values I want?
With the "COUNT" values, I was able to generate a bathymetry map, but the values in the legend are not correct..
Thanks in advance.