seamonas

A package to plot survey and density maps.

Miriam Lerma
2023-04-16

seamonas

A package with functions to make maps

1. Intro

Contains data:
- Data from a random generated survey in CRS 3035 and CRS 4326
- A grid generated using the function create_grid in CRS 3035

Contains functions:
- transform_survey
- subset_grid
- grid_densities
- plot_density
- add_breaks
- add_legend
- add_theme

2. Installation

You can install the development version of seamonas from GitHub with:

# install.packages("devtools")
devtools::install_github("MiriamLL/seamonas")

3. Data

head(survey_4326)

survey data

Data from a survey including longitude, latitude, timestamp

survey_4326<-survey_4326
ggplot2::ggplot()+
    ggplot2::geom_point(data=survey_4326,
                        ggplot2::aes(x=longitude, y= latitude, color=date),size = 1, shape = 16) 

density data

A data frame with survey data including observations

density_survey

grid 5x5

A grid 5x5 in CRS 3035

grid5x5_3035<-grid5x5_3035
plot(grid5x5_3035)

surveyed grid

The surveyed grid, this means the grid cells were data was collected

grid_surveyed

4. Survey grid

transform_survey

A function to transform data collected in latitude and longitude from degrees, transform from 4326 to 3035

survey_3035<-transform_survey(survey_data=survey_4326,
                 column_latitude='latitude',
                 column_longitude='longitude',
                 from_CRS=4326,
                 to_CRS=3035)

subset_grid

Add values to geometries of the grid, each square is a geometry or polygon There will be warning that variables are assumed to be spatially constant throughout all geometries Will print a plot and return the grids with data

grid_surveyed<-subset_grid(survey_grid=grid5x5_3035,
                      survey_data=survey_3035,
                      grid_identifier='grid_id')

Plot to check grid

ggplot2::ggplot()+
  ggplot2::geom_sf(data = grid_surveyed, colour = "#42a921", fill= '#bde0fe',alpha=0.9)+
  ggplot2::geom_sf(data = survey_3035)+
  NULL

5. Densities grid

A series of functions to go from a data frame of surveyed data to a grid

transform_survey

A function to transform the CRS

densities_3035<-transform_survey(survey_data=density_survey, 
                 column_latitude='latitude',
                 column_longitude='longitude',
                 from_CRS=4326,
                 to_CRS=3035)

grid_densities

A function to keep only grids with data

density_grid<-subset_density(density_survey=densities_3035,column_density='densities',
                             survey_grid=grid_surveyed,grid_identifier='grid_id')

Check the data

ggplot2::ggplot()+
  ggplot2::geom_sf(data = density_grid,mapping = ggplot2::aes(fill = mean_density), lwd = 0, colour = NA)

6. Plot densities

plot_density

Base data

my_CRS<-3035
Europa<-sf::st_transform(GermanNorthSea::German_land, my_CRS)
EEZ<-sf::st_transform(GermanNorthSea::German_EEZ, my_CRS)
color_land='#f7bf54'
color_water='#3668b4'
xval<-c(3910000,4250000)
yval<-c(3380000,3680000)

Provide density grid and mean densities

density_plot<-ggplot2::ggplot()+
    # maps
    ggplot2::geom_sf(data = EEZ, colour = 'black', fill = color_water)+
    ggplot2::geom_sf(data = Europa, colour = 'black', fill = color_land)+
    ggplot2::geom_sf(data = density_grid,
                     mapping = ggplot2::aes(fill = mean_density), lwd = 0, colour = NA) + 
  ggplot2::coord_sf(xlim = xval, ylim = yval)+

    NULL
density_plot

add_breaks

A function to add color palette and breaks in the legend, will vary with the species density estimates

plot_wbreaks<-add_breaks(density_plot=density_plot,
                     legendbreaks=c(0,0.5,1,1.5,2.0),
                     legendlimits=c(0,2),
                     legendlabels=c('     0','   0.5','   1.0','   1.5','> 2.0'))
plot_wbreaks

add_legend

A function to add the legend inside the plot

plot_wlegend<-add_legend(
  plot_wbreaks=plot_wbreaks,
  legtx=3905000,
  legty=3510000,
  legxy=c(0.11, 0.21),
  xval=c(3910000,4250000),
  yval=c(3380000,3680000))
plot_wlegend

add_theme

A function to define the theme

plot_wtheme<-add_theme(plot_wlegend = plot_wlegend)
plot_wtheme