Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...


MS Teams is a workspace for real-time collaboration and communication, meetings, file and app sharing, and even the occasional emoji! All in one place, all in the open, all accessible to everyone.











%appdata%\Microsoft\Teams





Technical Guideline Series
Technical Guideline Series







library(RColorBrewer)
library(ggplot2)
library(sf)
library(rnaturalearth)




RColorBrewer::display.brewer.all()RColorBrewer::display.brewer.all(colorblindFriendly = TRUE)RColorBrewer::display.brewer.pal(n = 5, name = 'YlOrRd')RColorBrewer::brewer.pal(n = 5, name = "YlOrRd")
## [1] "#FFFFB2" "#FECC5C" "#FD8D3C" "#F03B20" "#BD0026"land <- ne_countries(scale = 110, returnclass = "sf") # Downloads land polygons
cities <- read_sf("ne_110m_populated_places.shp") # Downloads the large cities points dataset
robin <- "+proj=robin +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs"# Defines Projection
# Converts to Robinson
land <- st_transform(land, crs = robin)
cities <- st_transform(cities, crs = robin)ggplot(cities) +
geom_sf(data = land, # adds land for reference
col = NA,
fill = "gray60") +
geom_sf(aes(color = POP_MIN/1000000)) + # Assigns the colour of the large cities to their minimum population size
scale_color_gradient( # used with continuous data
low = "#FFFFB2",
high = "#BD0026") +
labs(color = "Population (millions)") +
theme(legend.position = "bottom", # Places legend on the bottom
panel.background = element_blank(), # controls the background panel colour
panel.grid.major = element_line(color = "grey80")) # controls the grid line colour ggplot(land) +
geom_sf(aes(fill = continent, color = continent)) + # Fill and colour are the same to effective remove borders
scale_color_brewer(palette = "Dark2") + # Uses a RColorBrewer palette
scale_fill_brewer(palette = "Dark2") +
theme(legend.position = "bottom",
legend.title = element_blank(),
panel.background = element_blank(),
panel.grid.major = element_line(color = "grey80")) library(sf)
library(dplyr)
library(magrittr)
library(rnaturalearth)
library(graticule)
library(ggplot2)
library(ggspatial)


robin <- "+proj=robin +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs"
# Land polygons from rnaturalearth pckage
world <- rnaturalearth::ne_download(scale = 10, type = 'land', category = 'physical', returnclass = "sf") # sf mulitpologyon
## OGR data source with driver: ESRI Shapefile
## Source: "C:\Users\jkumagai\AppData\Local\Temp\Rtmp8GjHuK", layer: "ne_10m_land"
## with 11 features
## It has 3 fields
world_robin <- sf::st_transform(world, crs = robin) # changes the projection
# ocean from rnaturalearth package
ocean <- rnaturalearth::ne_download(scale = 10, type = 'ocean', category = 'physical', returnclass = "sf")
## OGR data source with driver: ESRI Shapefile
## Source: "C:\Users\jkumagai\AppData\Local\Temp\Rtmp8GjHuK", layer: "ne_10m_ocean"
## with 1 features
## It has 3 fields
ocean <- sf::st_transform(ocean, crs = robin) # changes the projection
ocean <- ocean[,1]# Creates latitude and longitude labels and graticules
lat <- c(-90, -60, -30, 0, 30, 60, 90)
long <- c(-180, -120, -60, 0, 60, 120, 180)
labs <- graticule::graticule_labels(lons = long, lats = lat, xline = -180, yline = 90, proj = robin) # labels for the graticules
lines <- graticule::graticule(lons = long, lats = lat, proj = robin) # graticules # Global Map
par(mar = c(0,3,0,2)) # Adjusts the edges of the frame
plot(lines, lty = 5, col = "lightgrey") # plots graticules
plot(ocean, col = alpha("lightskyblue", 0.3), add = TRUE) # plots ocean polygons
plot(world_robin[,1], col = "white", add = TRUE) # plots Land boundaries
text(subset(labs, labs$islon), lab = parse(text = labs$lab[labs$islon]), pos = 3, cex = 0.7, xpd = NA) # plots longitude labels
text(subset(labs, !labs$islon), lab = parse(text = labs$lab[!labs$islon]), pos = 2, cex = 0.7, xpd = NA) # plots latitude labels
box(which = "plot", lty = "solid") # Map frame ggplot() +
geom_sf(data = world, color = "black", fill = "lightgrey") + # plots the land polygons
coord_sf(xlim = c(-117.5, -86.5), ylim = c(14.5, 33.0)) + # sets the maps extent
theme(panel.grid.major = element_line(color = gray(.5), # sets latitude and longitude lines
linetype = "dashed", size = 0.5),
panel.background = element_rect(fill = "#b3e5fc"), # sets background panel color
panel.border = element_rect(colour = "black", fill=NA, size=0.5)) + # sets panel border
ggspatial::annotation_north_arrow(location = "bl", which_north = "true", # sets north arrow
style = north_arrow_minimal,
pad_x = unit(-0.1, "in"), pad_y = unit(0.45, "in")) +
ggspatial::annotation_scale(location = "bl") # sets scale bar# Loading data
grey_areas <- read_sf("country_borders/grey_areas.shp")
solid_borders <- read_sf("country_borders/solid_borders.shp")
dashed_borders <- read_sf("country_borders/dashed_borders.shp")
dotted_borders <- read_sf("country_borders/dotted_borders.shp")
major_lakes <- read_sf("country_borders/Major_Lakes.shp")
# Project data
grey_areas <- st_transform(grey_areas, robin)
solid_borders <- st_wrap_dateline(solid_borders) # corrects borders that cross the dateline
solid_borders <- st_transform(solid_borders, robin)
dashed_borders <- st_transform(dashed_borders, robin)
dotted_borders <- st_transform(dotted_borders, robin)
major_lakes <- st_transform(major_lakes, robin)# Global Map from earlier
par(mar = c(0,3,0,2)) # Adjusts the edges of the frame
plot(lines, lty = 5, col = "lightgrey") # plots graticules
plot(ocean, col = alpha("lightskyblue", 0.3), lwd = 0.2, add = TRUE) # plots ocean polygons
plot(world_robin[,1], col = "white", border = NA, lwd = 0.2, add = TRUE) # plots land boundaries
# Plot borders
plot(grey_areas, col = "grey30", border = NA, add = TRUE) # plot grey areas
plot(solid_borders, col = "grey40", lwd = 0.2, add = TRUE) # plot solid borders
plot(dashed_borders, col = "grey40", lwd = 0.2, lty = "dashed", add = TRUE) # plot dashed borders
plot(dotted_borders, col = "grey40", lwd = 0.2, lty = "dotted", add = TRUE) # plot dotted borders
plot(major_lakes, col = "lightblue2", lwd = 0.2, border = "grey40", add = TRUE) # plot major lakes
# Add lables to graticules
text(subset(labs, labs$islon), lab = parse(text = labs$lab[labs$islon]), pos = 3, cex = 0.7, xpd = NA) # plots longitude labels
text(subset(labs, !labs$islon), lab = parse(text = labs$lab[!labs$islon]), pos = 2, cex = 0.7, xpd = NA) # plots latitude labels
box(which = "plot", lty = "solid") # Map frame 
Technical Guideline Series
Technical Guideline Series
Technical Guideline Series






# Install the package inborutis and load into library
library(inborutils)
doi <- "10.5281/zenodo.3923633"
local_path <- "data"
inborutils::download_zenodo(doi, local_path, quiet = TRUE)
list.files(local_path)# Install these packages and then load them into library
library(magrittr) # Package for the pipe function
library(sf) # Package to read the vector data
path <- "data/ipbes_regions_subregions_shape_1.1.zip"
unzip(path, # pathname of the zip file
exdir = local_path) # pathname to extract files to
file <- list.files(path = local_path, pattern = "\\.shp$", full.names = T)
data <- sf::st_read(file, quiet = T)
# Plot some data
Mexico <- data %>% filter(ISO_3 == "MEX")
plot(Mexico[,1], main = "Mexico")library(sf)
library(dplyr)
library(magrittr)
library(FAOSTAT)
library(httr) # to download data off of Zenodo
library(rnaturalearth) # download ocean data from natural earth
library(graticule) # for mapping FAOSTAT::download_faostat_bulk("http://fenixservices.fao.org/faostat/static/bulkdownloads/Population_E_All_Data_(Normalized).zip", getwd())recordID <- "3923633"
url_record <- paste0("https://zenodo.org/api/records/", recordID)
record <- httr::GET(url_record)
record # Status 200 indicates a successful download
## Response [https://zenodo.org/api/records/3928281]
## Date: 2021-02-04 13:31
## Status: 200
## Content-Type: application/json
## Size: 6.41 kBView(content(record)) # view displays the output in a human readable form within R Studio# Contains the url to download the shapefile
url_shape <- content(record)$files[[5]]$links$download
httr::GET(url_shape, write_disk("ipbes_regions_subregions.zip", overwrite = T)) # Downloads shapefile
## Response [https://zenodo.org/api/files/581f2706-24e9-43d0-a776-0ce97f377938/ipbes_regions_subregions_shape_1.1.zip]
## Date: 2021-02-04 13:31
## Status: 200
## Content-Type: application/octet-stream
## Size: 175 MB
## <ON DISK> C:\Users\jkumagai\Documents\IPBES\R\Geoinformatics\Technical Guidelines Series\Mapping Guidelines v2\ipbes_regions_subregions.zip
unzip("ipbes_regions_subregions.zip") # unzips shapefilepop_raw <- FAOSTAT::read_faostat_bulk("Population_E_All_Data_(Normalized).zip") # load the population data using FAOSTAT's built in function
shape <- sf::st_read("IPBES_Regions_Subregions2.shp") # shapefile
## Reading layer `IPBES_Regions_Subregions2' from data source `C:\Users\jkumagai\Documents\IPBES\R\Geoinformatics\Technical Guidelines Series\Mapping Guidelines v2\IPBES_Regions_Subregions2.shp' using driver `ESRI Shapefile'
## Simple feature collection with 257 features and 5 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -180 ymin: -90 xmax: 180 ymax: 83.65833
## geographic CRS: WGS 84crs_robin <- "+proj=robin +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs"
shape <- sf::st_transform(shape, crs_robin)ocean <- rnaturalearth::ne_download(scale = 10, type = 'ocean', category = 'physical', returnclass = "sf")
## OGR data source with driver: ESRI Shapefile
## Source: "C:\Users\jkumagai\AppData\Local\Temp\RtmpqmEyBR", layer: "ne_10m_ocean"
## with 1 features
## It has 3 fields
ocean <- sf::st_transform(ocean, crs = crs_robin) # changes the projection
ocean <- ocean[,1]pop_2018 <- pop_raw %>%
dplyr::filter(element == "Total Population - Both sexes" &
year == 2018) %>%
dplyr::select(area_code, # these columns are selected from the original data
area,
element,
year,
unit,
value)tail(pop_2018$area, 34)
## [1] "World"
## [2] "Africa"
## [3] "Eastern Africa"
## [4] "Middle Africa"
## [5] "Northern Africa"
## [6] "Southern Africa"
## [7] "Western Africa"
## [8] "Americas"
## [9] "Northern America"
## [10] "Central America"
## [11] "Caribbean"
## [12] "South America"
## [13] "Asia"
## [14] "Central Asia"
## [15] "Eastern Asia"
## [16] "Southern Asia"
## [17] "South-Eastern Asia"
## [18] "Western Asia"
## [19] "Europe"
## [20] "Eastern Europe"
## [21] "Northern Europe"
## [22] "Southern Europe"
## [23] "Western Europe"
## [24] "Oceania"
## [25] "Australia and New Zealand"
## [26] "Melanesia"
## [27] "Micronesia"
## [28] "Polynesia"
## [29] "European Union"
## [30] "Least Developed Countries"
## [31] "Land Locked Developing Countries"
## [32] "Small Island Developing States"
## [33] "Low Income Food Deficit Countries"
## [34] "Net Food Importing Developing Countries"
pop_2018 <- pop_2018[1:237, ] # Selects the first 237 records, thus removing the last 34 which are aggregated datapop_2018 <- FAOSTAT::translateCountryCode(data = pop_2018, from = "FAOST_CODE", to = "ISO3_CODE", "area_code") # Add's the ISO Code to the data
##
## NOTE: Please make sure that the country are matched according to their definition
## Warning in FAOSTAT::translateCountryCode(data = pop_2018, from = "FAOST_CODE", : The following entries does not have 'ISO3_CODE' available
## FAOST_CODE ISO3_CODE
## 53 351 <NA>
## 234 277 <NA>
## OFFICIAL_FAO_NAME
## 53 China (China mainland, Hong Kong SAR, Macao SAR, Taiwan)
## 234 the Republic of South Sudanpop_2018[230,2] <- "SSD" # South Sudan
pop_2018 <- na.omit(pop_2018) # removes China (including other areas)colnames(shape)[2] <- "ISO3_CODE"
regions <- shape %>%
as.data.frame() %>% # drops the spatial attributes
dplyr::select(ISO3_CODE, Region, Sub_Region) # filters the columns
pop_2018 <- dplyr::left_join(x = pop_2018, y = regions, by = "ISO3_CODE") %>% # Joins data
tidyr::drop_na() # conveenient function from tidyr package pop_2018 <- pop_2018 %>%
dplyr::group_by(Region) %>% # Grouping by regions
dplyr::mutate(region_pop = sum(value)/1000) %>% # calculates total population (millions) per region
dplyr::ungroup() %>%
dplyr::group_by(Sub_Region) %>% # Grouping by sub-region
dplyr::mutate(sub_region_pop = sum(value)/1000) %>% # calculates total population (millions) per sub-region
dplyr::ungroup()
pop_2018
## # A tibble: 234 x 11
## FAOST_CODE ISO3_CODE area element year unit value Region Sub_Region
## <int> <chr> <chr> <chr> <int> <chr> <dbl> <chr> <chr>
## 1 1 ARM Arme~ Total ~ 2018 1000~ 2.95e3 Europ~ Eastern E~
## 2 2 AFG Afgh~ Total ~ 2018 1000~ 3.72e4 Asia ~ South Asia
## 3 3 ALB Alba~ Total ~ 2018 1000~ 2.88e3 Europ~ Central a~
## 4 4 DZA Alge~ Total ~ 2018 1000~ 4.22e4 Africa North Afr~
## 5 5 ASM Amer~ Total ~ 2018 1000~ 5.55e1 Asia ~ Oceania
## 6 6 AND Ando~ Total ~ 2018 1000~ 7.70e1 Europ~ Central a~
## 7 7 AGO Ango~ Total ~ 2018 1000~ 3.08e4 Africa Southern ~
## 8 8 ATG Anti~ Total ~ 2018 1000~ 9.63e1 Ameri~ Caribbean
## 9 9 ARG Arge~ Total ~ 2018 1000~ 4.44e4 Ameri~ South Ame~
## 10 10 AUS Aust~ Total ~ 2018 1000~ 2.49e4 Asia ~ Oceania
## # ... with 224 more rows, and 2 more variables: region_pop <dbl>,
## # sub_region_pop <dbl>data <- dplyr::full_join(x = shape, y = pop_2018, by = "ISO3_CODE")data_region <- data %>% # this dissolves the data by region
dplyr::group_by(Region.x) %>%
dplyr::summarise(region_pop2 = sum(value, na.rm = T)/1000) %>%
sf::st_cast()
data_subregion <- data %>% # this dissolves the data by subregion
dplyr::group_by(Sub_Region.x) %>%
dplyr::summarise(sub_region_pop2 = sum(value, na.rm=T)/1000) %>%
sf::st_cast()data_region$region_pop2 <- as.character(round(data_region$region_pop2 )) # Treats the values as groups so the legend displays correctly
data_region$region_pop2[5] <- "0927" # Ensures the legend displays correctly
# Plotting by regions
palette <- c("grey","aliceblue", "lightskyblue", "dodgerblue", "dodgerblue4") # colors
plot(data_region[,2], pal = palette, main = "Total population (millions) in 2018 per region")# Creates latitude and longitude labels and graticules
lat <- c(-90, -60, -30, 0, 30, 60, 90)
long <- c(-180, -120, -60, 0, 60, 120, 180)
labs <- graticule::graticule_labels(lons = long, lats = lat, xline = -180, yline = 90, proj = crs_robin) # labels for the graticules
lines <- graticule::graticule(lons = long, lats = lat, proj = crs_robin) # graticules par(mar = c(2,3,1,2)) # Adjusts the edges of the frame
plot(lines, lty = 5, col = "lightgrey", main = "Total population (millions) in 2018 per region") # plots graticules
plot(ocean, col = ggplot2::alpha("slategray1", 0.3), add = TRUE)
plot(data_region[,2], pal = palette, add = TRUE)
text(subset(labs, labs$islon), lab = parse(text = labs$lab[labs$islon]), pos = 3, xpd = NA) # plots longitude labels
text(subset(labs, !labs$islon), lab = parse(text = labs$lab[!labs$islon]), pos = 2, xpd = NA) # plots latitude labels
legend("bottom", # adding the legend last
legend = (data_region %>% pull(region_pop2) %>% sort()),
fill = palette,
horiz = TRUE, bty = "n")
box(which = "plot", lty = "solid") # Map frame plot(data_subregion[,2], main = "Total population (millions) in 2018 per sub-region", breaks = "quantile")library(terra)
library(raster)
library(graticule)
library(rgdal)
library(rworldmap)crs <- "+proj=robin +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m"prec <- raster::getData(name = "worldclim", var = "prec", res = 10)[[1]] # load data
plot(prec)raster::crs(prec)
## CRS arguments: +proj=longlat +datum=WGS84 +no_defsjp <- terra::rast(prec$prec1)
jp <- jp * 1 # to deal with NAs in this datasaet
rob <- terra::project(jp, crs, mask=TRUE)plot(rob) #Plot the raster# Creates latitude and longitude labels and graticules
lat <- c(-90, -60, -30, 0, 30, 60, 90)
long <- c(-180, -120, -60, 0, 60, 120, 180)
labs <- graticule::graticule_labels(lons = long, lats = lat, xline = -180, yline = 90, proj = crs) # labels for the graticules
lines <- graticule::graticule(lons = long, lats = lat, proj = crs) # graticules plot(rob,axes = F) #Plot the raster
plot(lines, lty = 5, col = "grey", add = TRUE) # plots graticules
text(subset(labs, labs$islon), lab = parse(text = labs$lab[labs$islon]), pos = 3, xpd = NA) # plots longitude labels
text(subset(labs, !labs$islon), lab = parse(text = labs$lab[!labs$islon]), pos = 2, xpd = NA) # plots latitude labelsworldmap <- rworldmap::getMap(resolution = "coarse") # Load countries
raster::crs(worldmap)
## CRS arguments:
## +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs
plot(worldmap) # Plot world map (vector)
## Warning in wkt(obj): CRS object has no commentworldmap <- sp::spTransform(worldmap,crs) # Project to Robinson
## Warning in spTransform(xSP, CRSobj, ...): NULL source CRS comment, falling back
## to PROJ string
## Warning in wkt(obj): CRS object has no comment
plot(worldmap)
plot(lines, lty = 5, col = "grey", add = TRUE) # plots graticules
text(subset(labs, labs$islon), lab = parse(text = labs$lab[labs$islon]), pos = 3, xpd = NA) # plots longitude labels
text(subset(labs, !labs$islon), lab = parse(text = labs$lab[!labs$islon]), pos = 2, xpd = NA) # plots latitude labels## Vector & Raster
plot(rob,axes = F) # Plot the raster
plot(worldmap,add=T) # Plot the vector data
plot(lines, lty = 5, col = "grey", add = TRUE) # plots graticules
text(subset(labs, labs$islon), lab = parse(text = labs$lab[labs$islon]), pos = 3, xpd = NA) # plots longitude labels
text(subset(labs, !labs$islon), lab = parse(text = labs$lab[!labs$islon]), pos = 2, xpd = NA) # plots latitude labels





For email & distribution lists, sharing, configuring settings, and more.
















Technical Guideline Series
Technical Guideline Series
library(magrittr) # for the pipe operator
library(sf) # we use sf package to handle vector data
States <- raster::getData("GADM", country = "United States", level = 1) # Downloads data from GADM
Utah_sf <- st_as_sf(States) %>% dplyr::filter(NAME_1 == "Utah") # Select just the state of Utah for simplicity Utah_sf %>%
st_write("Utah_geopackage.gpkg", # Uses the GPKG driver of the GDAL library
layer = "Utah") # Names the layer, as a GeoPackage can have multiple layers Utah_test <- st_read("Utah_geopackage.gpkg",
layer = "Utah")# Export
Utah_sf %>%
write_sf("Utah_shapefile.shp")
# Read
Utah_test2 <- read_sf("Utah_shapefile.shp")# Export
Utah_sf %>%
st_write("Utah.geojson",
driver = "GeoJSON",
layer_options = "RFC7946=YES")
# Read
Utah_test3 <- read_sf("Utah.geojson")st_crs(Utah_sf) # check projection
## Coordinate Reference System:
## User input: +proj=longlat +datum=WGS84 +no_defs
## wkt:
## GEOGCRS["unknown",
## DATUM["World Geodetic System 1984",
## ELLIPSOID["WGS 84",6378137,298.257223563,
## LENGTHUNIT["metre",1]],
## ID["EPSG",6326]],
## PRIMEM["Greenwich",0,
## ANGLEUNIT["degree",0.0174532925199433],
## ID["EPSG",8901]],
## CS[ellipsoidal,2],
## AXIS["longitude",east,
## ORDER[1],
## ANGLEUNIT["degree",0.0174532925199433,
## ID["EPSG",9122]]],
## AXIS["latitude",north,
## ORDER[2],
## ANGLEUNIT["degree",0.0174532925199433,
## ID["EPSG",9122]]]]# Export
st_write(Utah_sf, "Utah.kml", driver = "kml")
# Read
Utah_test4 <- st_read("Utah.kml")library(raster)
# Create raster to export
artwork <- raster() %>%
setValues(runif(ncell(.))) # fill with random values
# Export
writeRaster(artwork, "artwork.tif")raster("artwork.tif")
## class : RasterLayer
## dimensions : 180, 360, 64800 (nrow, ncol, ncell)
## resolution : 1, 1 (x, y)
## extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +no_defs
## source : artwork.tif
## names : artwork
## values : 1.338031e-05, 0.9999878 (min, max)library(stars)
# Writing a Geopackage
artwork %>%
st_as_stars %>% # this converts the RasterLayer to a stars object
write_stars("artwork.gpkg",
driver = "GPKG")
# Read the GeoPackage
artwork_gpkg_stars <- read_stars("artwork.gpkg") %>%
as("Raster")
artwork_gpkg_stars
## class : RasterLayer
## dimensions : 180, 360, 64800 (nrow, ncol, ncell)
## resolution : 1, 1 (x, y)
## extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +no_defs
## source : memory
## names : layer
## values : 1.338031e-05, 0.9999878 (min, max)library(ncdf4)
data(volcano) # store volcano dataset z <- 10*volcano # matrix of elevations
x <- 100*(1:nrow(z)) # meter spacing (S to N)
y <- 100*(1:ncol(z)) # meter spacing (E to W)# Define the netcdf coorindate variables
dim1 <- ncdim_def(name = "EW", units = "meters", vals = as.double(x)) # Defines longitude
dim2 <- ncdim_def(name = "SN", units = "meters", vals = as.double(y)) # Defines latitude
# Define the empty netcdf variable (elevation)
fillvalue <- 1e32
dlname <- "Elevation"
elevation_def <- ncvar_def("Elevation", units = "meters", list(dim1,dim2), fillvalue, dlname , prec="double")# create netCDF file and put arrays
file_volcano <- nc_create("Volcano.nc",list(elevation_def),force_v4=TRUE)
# Add variables into the file
ncvar_put(file_volcano, elevation_def, z)
# Get a summary of the created file:
file_volcano
## File Volcano.nc (NC_FORMAT_NETCDF4):
##
## 1 variables (excluding dimension variables):
## double Elevation[EW,SN] (Contiguous storage)
## units: meters
## _FillValue: 1e+32
##
## 2 dimensions:
## EW Size:87
## units: meters
## long_name: EW
## SN Size:61
## units: meters
## long_name: SNnc_close(file_volcano)# First step is to open the file
example <- nc_open("Volcano.nc")
example
## File Volcano.nc (NC_FORMAT_NETCDF4):
##
## 1 variables (excluding dimension variables):
## double Elevation[EW,SN] (Contiguous storage)
## units: meters
## _FillValue: 1e+32
##
## 2 dimensions:
## EW Size:87
## units: meters
## long_name: EW
## SN Size:61
## units: meters
## long_name: SNlon <- ncvar_get(example,"EW") # longitude
lat <- ncvar_get(example, "SN") # latitude
elevation <- ncvar_get(example, "Elevation") # variablefilled.contour(lon,lat,elevation, color = terrain.colors, asp = 1)# csv
write.csv(mtcars, # Dataset
"mtcars.csv", # Name of file
fileEncoding="UTF-8") # Specifies encoding (UTF-8 preferred)
# tab
write.table(mtcars, # Dataset
file = "mtcars.txt", # Name of file
sep = "\t", # Tab delineation
fileEncoding = "UTF-8") # Specifies encoding (UTF-8 preferred)svg("example_1.svg") # SVG graphics device and file name
plot(rnorm(100), main = "Example Graph") # Plot your graph
dev.off() # Close the graphics device setEPS()
postscript("example_2.eps")
plot(rnorm(100), main = "Example Graph") # Plot your graph
dev.off()pdf("example_3.pdf",
width = 4, height = 4, # Width and height in inches
paper = "A4") # Paper size
plot(rnorm(100), main = "Example Graph") # Plot your graph
dev.off()png("example_4.png",
width = 4, height = 4,
units = "in", # Units in inches
res = 300) # resolution in dpi
plot(rnorm(100), main = "Example Graph") # Plot your graph
dev.off()jpeg("example_5.jpeg", width = 4, height = 4, units = 'in', res = 300)
plot(rnorm(100), main = "Example Graph") # Plot your graph
dev.off()tiff("example_6.tiff", width = 4, height = 4, units = "in", res = 300)
plot(rnorm(100), main = "Example Graph") # Plot your graph
dev.off()