
I am rather fond of a good map, and especially a good map that has some kind of archaeological content. Due to this I tend to spend an inordinate amount of time both making maps and learning new and interesting ways to make them. This has led to me now being something of the “GIS-guy” at my new workplace. Well, the “QGIS guy” as I spent around 5 minutes working with ArcGIS in about 2012 before realising that it would be better for my wallet to focus on the open source side of things. Not that I mind being the QGIS-guy, I am much happier working at a computer than freezing half to death somewhere in the north of Germany in the middle of winter. FAR happier! XD
We recently finished an excavation at the beginning of December last year. Gott sei dank, it is bloody nippy out at the moment! Quite where it was I am not allowed to say because the German authorities are extremely sensitive about that sort of thing. I can however talk about it in more general terms. Which I am going to do as it was quite different to everywhere else that I have dug in my career so far. Almost every dig that I have worked on has been in something of a rural setting. This has meant that there has, in general, been no really complicated stratigraphy.
Stratigraphy gets complicated when there has been a large amount of activity in a place and later activities have disturbed or cut through earlier activities. So in a city or town that has been continuously occupied for the last 2,000 years there could be a house from the 1920s whose foundations cut through the remains of a medieval building that stood on the same spot which itself was cut into a Roman structure. It can be a real puzzle to figure out.

This isn’t often the case in a rural context where perhaps houses and barns may have been built one atop another but not usually repeatedly over thousands of years. I’m writing in a northern European context here, it is quite possibly very different elsewhere.
The techniques for excavating in a rural setting are also quite different to an urban one. A rural setting will often, in my experience, be a lot simpler to excavate and document. In the areas I have worked we will use an excavator, a “Bagger” in the local parlance, to strip away the upper soil until we reach the soil set down in the last glacial maximum. We will then record what we see in a flat plane before excavating features individually. This initial recording will give us a plan drawing looking something like this.
We can see from this that we have some sort of structure, possibly a small house or barn. Lovely isn’t it?
It’s also pretty straight forward to interpret compared to urban excavations which can, as seen above, have extremely complicated stratigraphy. I haven’t done much in the way of urban excavation and haven’t done any analysis or GIS work with those projects that I have worked on.
I started work with a new firm this last summer and my first dig with them was in an urban setting but was quite unlike anything I have worked on before, rural or urban. There was little in the way of structures aside from a smattering of posts, possibly animal enclosures, and a couple of large trenches criss-crossing the excavated area. What there was however was a metric f*ck-ton of animal skeletons. Some appearing to have been intentionally buried, others less so.
In order to try and figure out what was going on there the local heritage body asked for a document with information on each of the skeletons with their locations, photographs, and so on. Seeing as I’m the GIS/map nerd in the office that task was given to me. Putting together a map that just shows the locations of each of the skeletons without the other documented features is a simple enough job using QGIS. The only problem here is that a map is, by its nature, two dimensional and it is important to be able to show the depth at which the skeletons were found in relation to one another.

In order to do this I decided to use a scatterplot diagram using the height above sea-level as the ‘Y’ axis and the point name/number as the ‘X’ axis. This would allow me to clearly show the difference in depth between the various skeletons. I am going to describe my method here so that, hopefully, others may find it useful and because my memory is absolutely awful and I would like to be able to refer back to something next time I have to do this.
My process can be broken down into 5 steps. Even if step one does have 8 ‘sub-steps’.
Steps
- Export data from QGIS as .csv
- Filter for useful points
- Select points relating to areas with skeletons
- Make a new layer
- Use Field Calculator to calculate mean coordinates
- Clean up ‘bemerkung’ fields with REGEX
- Create points layer from table
- Delete duplicates by attribute
- Export as .csv
- Read .csv into a dataframe in Rstudio
- Generate Scatterplot
- Tweak Scatterplot until it is ‘just so’
- Automate making a Scatterplot highlighting each point in turn.
Before starting I should talk briefly about how we excavated this particular site. Because of the particular issues with this particular site, rather than recording the entire area we broke it down into smaller areas, Flächezeichnung, focused on where we had seen archaeological features. We would then document and excavate these ‘Flz’ fully before moving onto the next one. This resulted in a plan drawing looking something like this below. More of a patchwork than a normal excavation with each outline being an excavated area.

To document each area we measure the outlines of the features in with a Total Station. Each point is recorded with a series of letters and numbers that denote things like what is being measured, its feature number, and so on. This data is then exported and imported into QGIS in order to draw the plan and begin analysis.
QGIS + Steps 1.1-1.8
My initial thought when approaching this problem was to use the DataPlotly plugin for QGIS. DataPlotly allows one to make number of attractive charts to help illustrate geospatial data. It’s a really useful plugin but, unfortunately, it isn’t very easily tweakable. I was able to generate a basic scatterplot but unable to highlight specific data points to show which skeleton was being discussed in the document.

To do this I needed first to generate a single coordinate that would represent the skeleton and the feature in which it was found. Within each ‘Flz’ we measured many, many, many points for the outlines of features, archaeological and geological, and anything found within such as pottery, glass, metal, and (of course) skeletons. This means that a single ‘Flz’ can have upwards of 500 individual measured points. I needed to reduce these down to a single point.
One of the sets of measurements we take are for something called “structure from motion”. SfM is a way of creating a three dimensional image from a set of two dimensional photographs. Each set of SfM photographs uses control points which are measured with the Total Station and then used to place the generated 3D model into the correct place in a map. These control points are evenly spaced around the Flz and so will be perfect for finding the mean average coordinates of the Flz as a whole.
Step 1.1: Filter the points layer for the value ‘SFM’ meaning that from this point on, when working with this points layer, QGIS will only work with those points.
Step 1.2: Open the Attribute Table of the points layer in QGIS. Then manually select each of the Flz containing skeletons.
Step 1.3: Export each of the selected points to a new temporary layer.
Step 1.4: Use the Graphical Modeler to run three regular expressions over the new points layer. The Graphical Modeller allows one to run a series of algorithms in a chain when you’re too lazy to do it multiple times. I made a model, see below, that ran the following expressions over the new layer.
mean("x", group_by:="bemerkung")
mean("y", group_by:="bemerkung")
mean("z", group_by:="bemerkung")
(‘bemerkung’ being the column containing the data referring to which Flz is being recorded)

This added three new columns to the Attribute Table of the new layer, mean_x, mean_y, and mean_z with each point containing the mean average coordinates for the group.
Step 1.5: This left me with a new layer made up only the SFM points. However, due to the way that we used to record SFM points in the field the ‘bemerkung’ column which I am using to group points together doesn’t simply read ‘FLZxxx’. Rather it reads SFM_FLZxxx_x’. So I needed to again use the Field Calculator to update the ‘bemerkung’ field and remove the extraneous characters.
regexp_replace("bemerkung", '^SFM_FZ|_\\d+$', '')
This expression essentially says: replace ‘SFM_FZ’ at the beginning (^SFM_FZ) and any trailing underscore and number at the end (_\\d+$) with an empty string. Cool.
Step 1.6: However this still leaves me with four points for each FLZ and I need a single point with the x, y, and z values from the ‘mean_x, y, and z’ values of my new ‘mean_values’ layer. The “easiest” way to do this is to use the ‘Create points layer from table’ tool which will create a nice central point for each FLZ. Well, it will create four central points which is no good.
Step 1.7: So, I then use the ‘Delete duplicates by attribute’ tool and, at last, I have a layer that I can feed into DataPlotly. However, as shown above, DataPlotly doesn’t really do what I need. So now I’m going to have to make it complicated.
Well, more complicated. :/
Step 1.8: Export the layer as a .csv, in this case it is called ‘tierskelett_flz_centroid.csv’. (Tier=animal, Skelett=skeleton)
R + RStudio
This is where it gets super nerdy.
Now we are going to start using ‘R’. R is a programming language that is especially good at data visualisation. We will be using this with a program called Rstudio which is a development environment that makes things a little bit easier to handle than just writing line after line of code.
Step 2:
In Rstudio I create a new RProject and a folder, in this case both called ‘tierskelett_plots’, into which I copy the .csv file exported from QGIS.
First up I want to read the .csv file into R so that R can treat it as a dataframe. I do this with the command:
readfile <- read.csv("tierskelett_flz_centroid.csv")
To ensure that it has been read correctly I can check the first few lines of the table with the following command:
head(readfile)
This will give a readout like something like this
bemerkung x y z
1 239 227539.0 6677714 1.757525
2 259 227545.5 6677727 2.509575
3 312 227549.1 6677731 2.230800
4 234 227539.0 6677714 2.027550
5 311 227557.3 6677734 2.491500
6 292 227550.8 6677726 2.272125
(the x and y coordinates above are nonsense as I wouldn’t want to be sharing actual location data with you animals.)
Step 3: Make a simple scatterplot to see that it works. To do this I use the following code:
> plot(readfile$bemerkung, readfile$z,
+ pch = 16, col = "blue",
+ xlab = "bemerkung", ylab = "z",
+ main = "Streudiagramm, das die Tiefenbeziehung von Tier-Skeletten darstellt.")
In the above code ‘pch’ refers to the form that the points will take in the scatterplot, the ‘plotting character’, which in this case, ’16’, is a circle. See the bottom of this article for a full list of all 24 possible plotting characters. ‘col’ refers to the colour of the points, ‘xlab’ and ‘ylab’ refer to the labels of the x and y axes, whilst ‘main’ refers to the title of the diagram. Which gives us the following plot. Not so different to the DataPlotly one generated in QGIS.
That’s nice, but I want a couple of extra things of my scatterplot. Firstly I want labels, and secondly I want a way to highlight a single point so that I can include the plot on each page of my document showing the skeleton in relation to others on the site.
Step 4:
First off to add the label I need to change my code like so:
> plot(readfile$bemerkung, readfile$z,
+ pch = 16, col = "blue",
+ xlab = "bemerkung", ylab = "z",
+ main = "Streudiagramm, das die Tiefenbeziehung von Tier-Skeletten darstellt.")
> text(readfile$bemerkung, readfile$z,
+ labels = readfile$bemerkung,
+ pos = 1, offset = 0.5, col = "black")
Here we tell R to add labels to the points by referencing the .csv column ‘bemerkung’ with the line “labels = readfile$bemerkung,”, with ‘pos’ being the position, ‘offset’ the (you guessed it) offset, and again ‘col’ being the colour. Unfortunately many of our points are quite close together and so the labels look really messy.
So, that’s not great and certainly not something that I would be wanting to send to the local heritage authority. Instead of the base R plotting functions we shall install a couple of other R packages which give extra functionalities. We will install ggplot2 which expands the possibilities with drawing plots and ggrepel which does really clever geometry stuff in order to prevent ggplot2 overlapping the labels. We install these with the following commands:
install.packages("ggplot2")
install.packages("ggrepel")
We then need to make sure that R will use these packages by adding them as libraries:
library(ggplot2) library(ggrepel)
Now we can generate the scatterplot with ggplot and ggrepel.
ggplot(data = readfile, aes(x = bemerkung, y = z, label = bemerkung)) +
geom_point(shape = 16, color = "blue") +
geom_text_repel(
box.padding = 0.5,
point.padding = 0.1,
force = 5,
nudge_x = 0.1,
segment.color = "black"
) +
labs(x = "bemerkung", y = "z", title = "Streudiagramm, das die Tiefenbeziehung von Tier-Skeletten darstellt.") +
theme(axis.line = element_line(color = "black", linewidth = 0.5),
plot.title = element_text(face = "bold"))
That is much better, but I would still like to tweak some things. I would like the points to be a touch larger for starters. I would also like to highlight the skeleton being referenced by making the point red and a different shape, a triangle, to the other points. When doing this ggplot will automatically place a legend to the right of the plot. I don’t however want this so will change the shape and colour of the ‘guides’ to “none”.
ggplot(data = readfile, aes(x = bemerkung, y = z, label = bemerkung)) +
geom_point(aes(shape = factor(bemerkung == 234), color = factor(bemerkung == 234)), size = 4) +
scale_shape_manual(values = c("FALSE" = 16, "TRUE" = 17)) +
scale_color_manual(values = c("FALSE" = "blue", "TRUE" = "red")) +
geom_text_repel(
box.padding = 0.5,
point.padding = 0.1,
force = 5,
nudge_x = 0.1,
segment.color = "black"
) +
labs(x = "bemerkung", y = "z", title = "Streudiagramm, das die Tiefenbeziehung von Tier-Skeletten darstellt.") +
theme(axis.line = element_line(color = "black", linewidth = 0.5),
plot.title = element_text(face = "bold")) +
guides(shape = "none", color = "none")
Super! Now I want to change the labeling of the axes to show that my y axis is the height above sea level and my x axis is the Flächenzeichnung.
ggplot(data = readfile, aes(x = bemerkung, y = z, label = bemerkung)) +
geom_point(aes(shape = factor(bemerkung == 234), color = factor(bemerkung == 234)), size = 4) +
scale_shape_manual(values = c("FALSE" = 16, "TRUE" = 17)) +
scale_color_manual(values = c("FALSE" = "blue", "TRUE" = "red")) +
geom_text_repel(
box.padding = 0.5,
point.padding = 0.1,
force = 5,
nudge_x = 0.1,
segment.color = "black"
) +
labs(x = "Flächenzeichnung", y = "Höhe über dem Meeresspiegel(m)", title = "Streudiagramm, das die Tiefenbeziehung von Tier-Skeletten darstellt.") +
theme(axis.line = element_line(color = "black", linewidth = 0.5),
plot.title = element_text(face = "bold")) +
guides(shape = "none", color = "none")
Dancer! Now I just need to make one of these for each Flächenzeichnung. But there are soooo many and I am really really lazy. So I should automate it. Which I do, like so!
for (point in unique(readfile$bemerkung)) {
point_data <- subset(readfile, bemerkung == point)
+ plot <- ggplot(data = readfile, aes(x = bemerkung, y = z, label = bemerkung)) +
geom_point(aes(shape = factor(bemerkung == point), color = factor(bemerkung == point)), size = 4) +
scale_shape_manual(values = c("FALSE" = 16, "TRUE" = 17)) +
scale_color_manual(values = c("FALSE" = "blue", "TRUE" = "red")) +
geom_label_repel(
data = readfile,
aes(label = bemerkung),
box.padding = 0.5,
point.padding = 0.1,
force = 5,
nudge_x = 0.2, # Adjust the horizontal positioning of the labels
nudge_y = -0.2, # Adjust the vertical positioning of the labels
segment.color = "black",
max.overlaps = Inf
) +
labs(x = "Flächenzeichnung", y = "Höhe über dem Meeresspiegel(m)", title = "Streudiagramm, das die Tiefenbeziehung von Tier-Skeletten darstellt") +
theme(axis.line = element_line(color = "black", linewidth = 0.5),
plot.title = element_text(face = "bold")) +
guides(shape = "none", color = "none")
+ ggsave(filename = paste0(point, ".png"), plot = plot, width = 9.02, height = 5.86, units = "in", path = "PATH_TO_THE_SAVE_FOLDER")
}
The code above will iterate through the dataframe, our imported .csv, and create a scatterplot styled as above, with slightly nicer labels, and save one plot per point in the defined folder.
TADA!
Right, now I can get on with making the full document for the local heritage folks. Unfortunately I can’t share that here as that will be containing actual sensitive archaeological data. Toodlepip!
Plotting Characters
- pch = 1: ●
- pch = 2: ⬟
- pch = 3: ▲
- pch = 4: ◆
- pch = 5: ■
- pch = 6: ▼
- pch = 7: ►
- pch = 8: ◄
- pch = 9: A
- pch = 10: B
- pch = 11: ⬠
- pch = 12: ⧊
- pch = 13: ⊞
- pch = 14: ⊠
- pch = 15: ■ (square)
- pch = 16: ● (circle)
- pch = 17: ▲ (triangle)
- pch = 18: ◆ (diamond)
- pch = 19: ⬥
- pch = 20: ⧇
- pch = 21: ⧄
- pch = 22: ⬝
- pch = 23: ⬢
- pch = 24: ⊏
*I was originally going to call this “Don’t have a cow man!”, but wanted to go for a slightly more obscure pop culture reference in order to highlight my nerd credentials. As though an article about using R to generate a scatterplot of archaeological features isn’t nerdy enough.
















