In this short post, I will show how to use the app() , lapp() , and tapp() functions from the terra package to apply functions to SpatRaster objects. These functions are useful for performing operations on raster data, such as calculating means or applying custom functions across layers. Aerial view of layered rock formations showing natural geological strata, representing the concept of working…
Introduction I like DuckDB 🦆. I am excited to see that it is now possible to use it with dplyr using the fantastic duckplyr package which gives us another way to bridge dplyr with DuckDB. When duckdb meets dplyr! Photo by DuckDB In this short post, I will show how duckplyr can be used to query parquet files hosted on an S3 bucket. I will use the duckplyr_df_from_parquet() function to read the…
This will be a quick one, but I thought it was worth sharing (at least for future me). I was recently trying to segment a line into points of equal distances. I must say that I spent too much time with the st_segmentize() function. I found that I would simply achieve this using st_line_sample() . Let me show you how. When your brain is super well synchronized with your camera’s retadator. Photo by…
In this blog post, I will show you how to read and transform spatial data hosted in the cloud with DuckDB 1 . I will use the nycflights13 , a popular dataset for learning data science . I will also use the sf package to manipulate spatial data. We will first start our journey by using DuckDB to read tabular data from parquet files from an online repository. Then with dbplyr as a backbend, we will…
It has been a while since I posted something! But today I wanted to quickly experiment and create a map where I could separate/explode the spatial geometries. Let’s first download the polygon data for Canada. canada <- rnaturalearth :: ne_states ( country = "canada" , returnclass = "sf" ) |> st_make_valid ( ) As we can see, there are three different regions. canada |> distinct ( region ) #> region…
Hanukkah of data 2022 If you are looking for some data science challenges, don’t look anymore, Hanukkah of Data is there for you. You can think of it as similar to Advent of Code but tailored toward data-oriented puzzles with only eight challenges. In this blog post, I will try to solve all the puzzles using R. Hanukkah of data 2022 Getting the data The first step of the challenge is to get the…
I am using renv quite a lot. Recently, I had to return to an older project that was using this package to manage package dependencies. When I tried to load tidyverse , I got the following message: > library (tidyverse) Error : package or namespace load failed for ‘tidyverse’ in dyn.load (file, DLLpath = DLLpath, ...) : unable to load shared object…
When plotting spatial data, such as a geographical map, maintaining a proper aspect ratio is important . Whereas knitr::plot_crop() works fine to crop a file, how can we do the same operation for a figure inside an R Markdown or a Quarto document? Thanks to knitr , this can be done with a hook . Let’s crop something! Photo by Ant Rozetsky on Unsplash I will use the polygon of Greenland to…
Today I was trying to read AMSR2 sea ice data . I was surprised to discover that the files do not include coordinates or projection information. Data and coordinates are contained in different files! Maybe to save some disk space ⁉️ The sea ice data is (for example) in a file named Arc_20201010_res3.125_pyres.nc.gz whereas the coordinates are included in a file name…
When writing dynamic documents in R (either R Markdown or Quarto), it can be useful to display model equations. I recently discovered equatiomatic , a very nice package that can do the job. Photo by Artturi Jalli on Unsplash The package can be installed from CRAN using install.packages("equatiomatic") . To explore the package’s functionalities, we will build a simple linear model using mtcars data…
Lately, I was working on a project and I needed to change the spatial resolution of a GeoTIFF to match that of another one. After looking around, I posted a question on Stackoverflow . After experimenting around, I decided to blog about my experience of changing the spatial resolution of GeoTIFF rasters. In this post, we will explore two ways to change the spatial resolution of a raster:…
If you are beginning in R, chances are that you have used read.csv() to import CSV files into R. While this function works perfectly fine, it can only read one file at a time. Hence, new R programmers often read multiple files successively and combine the data afterward. # Read all the data files df1 <- read.csv ( "file1.csv" ) df2 <- read.csv ( "file2.csv" ) df3 <- read.csv ( "file3.csv" ) df4 <-…
When creating maps, choosing an appropriate geographical projection is often a difficult task (at least for me). There are plenty of projections to choose from , and none can be qualified as the best one . It all depends on what you are trying to achieve. Websites like the projection wizard website offer a playground to experiment with different projections and how they look like depending on…
Introduction For a long time, I have been using the raster package to manipulate raster data in R. Slowly, I am trying to work my way out with the new stars package. In this post, I am exploring different ways to extract values from a raster at different geographic locations. For this exercise, I am using a Landsat 7 image that is provided within the stars package. Each pixel has a resolution of…
Recently, I had to make a ggplot2 graphic with data that contained dates. Let’s create some sample data with dates. n <- 10 df <- tibble ( x = seq ( as.Date ( "2020-01-01" ) , as.Date ( "2020-10-10" ) , length.out = n ) , y = rnorm ( n ) ) df #> # A tibble: 10 × 2 #> x y #> <date> <dbl> #> 1 2020-01-01 0.973 #> 2 2020-02-01 -1.21 #> 3 2020-03-03 1.15 #> 4 2020-04-04 0.438 #> 5 2020-05-05 -0.322 #>…
Recently I was participating in the 30DayMapChallenge where people were invited to make a map based on a different daily theme for one whole month. Announcing #30DayMapChallenge in November 2019! Create a map each day of the month with the following themes 🌍🌎🌏 No restriction on tools. All maps should be created by you. Doing less than 30 maps is fine. #gischat #geography #cartography #dataviz…