library(dplyr)
# do not keep these three eye colours
%>%
starwars filter(!eye_color %in% c("blue", "yellow", "green"))
UQRUG 27
meeting
Questions: ggplot2, species distribution modelling, anomalies in chronology, R Markdown, factoextra
2022-06-01: UQRUG 27
Attendees
- Stéphane: Library, here to help!
- Emma: looking for some help editing a graphic with ggplot2
- Rene: just tagging along
- Laura: working on GLMs
- Leonie: both tagging along and hoping for some help with the adehabitat package
- Chris: just tagging along
- David: using R on HPC
- Astrid: R Markdown issues
- Olalekan: just tagging along
- …and 6 other UQRUGers!
Topics discussed and code
- ggplot2 customisation: moving legend, filtering data out
- Cédric Scherer’s slides (with customisation of legend using the
guides()
function)
- Cédric Scherer’s slides (with customisation of legend using the
- Preparation for species distribution modelling. Convert dataframe to sf object with
st_as_sf()
, and will probably need to go from vector data to raster data withterra::rasterize()
- The CRAN Task View on spatial data lists a lot of useful packages
- Importing spatial points for dolphin occurrences, using sf. Constructing a convex hull from them and visualising on an interactive map:
# read CSV as dataframe
<- read.csv("Adehabitat.csv")
dolph
library(sf)
# convert the dataframe to an sf object
<- st_as_sf(dolph, coords = c("Longitude", "Latitude"))
dolph_sf # see it with default plot method
plot(dolph_sf)
# interactive map
library(tmap)
tmap_mode("view")
tm_shape(dolph_sf) +
tm_dots()
# convex hull
<- st_convex_hull(st_union(dolph_sf))
dolph_hull
# visualise both
tm_shape(dolph_hull) +
tm_borders() +
tm_shape(dolph_sf) +
tm_dots()
- Detecting anomalies in chronological sequence of a dataframe.
dplyr::lag()
anddplyr::lead()
functions can be used for comparisons.any()
andall()
help reducing many logical values to one. - R Markdown troubles: Rmd is self-contained and needs to include all the necessary code. Its working directory is by default the directory where the .Rmd file is saved.
- factoextra’s
fviz_pca*()
functions for PCA, colouring points per group.