install.packages("geomorph")Setup and Install Software
Morphometrics Lesson 1
Install Packages
First we need to install the software packages that we will use. To install a single R package, we use the install.packages function and put the package name in quotes
But to speed things up we can use the three lines of code below. Here we make a list of all the packages we want to have, check if they are installed or not, and then install all of the packages which are missing from our computer.
my_packages <- c("StereoMorph",
"Momocs",
"geomorph",
"Morpho",
"stringr",
"sfsmisc",
"pixmap",
"tiff",
"splancs",
"jpeg",
"mvMORPH",
"remotes",
"Rvcg")
not_installed <- my_packages[!(my_packages %in%
installed.packages()[ , "Package"])]
if(length(not_installed)) install.packages(not_installed)
#note that as of may 2026, momocs is not on cran so we might have to do this:
pak::pkg_install("MomX/Momocs") Load Packages
Now that the software is loaded, we can load the packages into R so that they are read to use. You’ll have to do this again each time you open R
Loading built-in datasets
some of our R pacakges have example data built in. We can load in that data to our R environment with the data function
#from the Momocs package, outlines of whisky and beer bottles
data(bot)
botOut (outlines)
- 40 outlines, 162 +/- 21 coords (in $coo)
- 2 classifiers (in $fac):
# A tibble: 40 × 2
type fake
<fct> <fct>
1 whisky a
2 whisky a
3 whisky a
4 whisky a
5 whisky a
6 whisky a
# ℹ 34 more rows
- also: $ldk
names(bot) [1] "brahma" "caney" "chimay" "corona"
[5] "deusventrue" "duvel" "franziskaner" "grimbergen"
[9] "guiness" "hoegardeen" "jupiler" "kingfisher"
[13] "latrappe" "lindemanskriek" "nicechouffe" "pecheresse"
[17] "sierranevada" "tanglefoot" "tauro" "westmalle"
[21] "amrut" "ballantines" "bushmills" "chivas"
[25] "dalmore" "famousgrouse" "glendronach" "glenmorangie"
[29] "highlandpark" "jackdaniels" "jb" "johnniewalker"
[33] "magallan" "makersmark" "oban" "oldpotrero"
[37] "redbreast" "tamdhu" "wildturkey" "yoichi"
Take a look at the outline of the bottle of Franziskaner, a Bavarian beer
bot[7] |> paper_grid() |> draw_outline()Now lets try visualizing some 2D landmark data. This example data describes head shape of the lungless salamander Plethodon using 12 landmarks.
First, load the data
#from the geomorph package
data(plethodon)Try displaying the landmark data for first specimen
plethodon$land[,,1] [,1] [,2]
[1,] 8.89372 53.77644
[2,] 9.26840 52.77072
[3,] 5.56104 54.21028
[4,] 1.87340 52.75100
[5,] 1.28180 53.18484
[6,] 1.24236 53.32288
[7,] 0.84796 54.70328
[8,] 3.35240 55.76816
[9,] 6.29068 55.70900
[10,] 8.87400 55.25544
[11,] 10.74740 55.43292
[12,] 14.39560 52.75100
And try plotting a subset of the data
plotAllSpecimens(plethodon$land[,,1:2],links = plethodon$links)Finally, plot some 3D data. This will open a new window.
Note: that if you are on MacOS 26 Tahoe, some 3D graphics stuff is bugged right now unless you upgrade to version 26.5 or higher and rebuild the
rglpackage. If you are on an earlier version of Tahoe, you might have to run thisoptions(rgl.useNULL = TRUE, rgl.printRglwidget = TRUE)first to get 3D visuals in R to work at all.
Some other installations
Some of our analyses might require additional software packages that cannot be installed directly through R. Most folks will have these things installed already, but I will leave these links here just in case
XQuartz for Mac: https://www.xquartz.org
ImageMagik: https://imagemagick.org/script/download.php
Exercise:
Try playing with the plotting functions in Momocs to render another outline shape (from data object bot or shapes within Momocs). Experiment with different colors, line types and thicknesses.