The leader of the FDP, the liberal party, here in Bremen has suggested banning non-EU citizens from attending or organising demonstrations in order to cut down on “imported” extremism. Let’s be clear here, he isn’t talking about non-EU citizens like me, he’s talking about brown people. Because there is a trend within German mainstream politics that extremism, and especially antisemitic extremism, is an imported thing. Germany, after all, dealt with all this following the second world war. They even built a monument to it in Berlin.
This annoyed me.
So I decided to grab a list of terrorist attacks in Germany in order to see exactly where the violent extremism that is tearing Germany apart comes from. I hit up wikipedia and downloaded the tables from this page and then took all the years from 2000 to present and combined them into a single file. I want to make a map of all the terror attacks since the year 2000 so as to be able to visualise the attacks, so I used a small python script to calculate the coordinates for each town/city with a terrorist attack. Click here to skip the nerdy bits
import pandas as pd
from geopy.geocoders import Nominatim
from pyproj import Transformer
# Load the CSV file
df = pd.read_csv('combined.csv')
# Initialize the geolocator
geolocator = Nominatim(user_agent="geoapiExercises")
# Initialize a transformer to convert to EPSG:3857 (ESRI:102100)
transformer = Transformer.from_crs("epsg:4326", "epsg:3857")
# Create two empty columns for X and Y coordinates
df['X'] = None
df['Y'] = None
# Function to get coordinates and transform them
def get_coordinates(town):
try:
# Get the location of the town
location = geolocator.geocode(town + ', Germany')
if location:
# Convert latitude and longitude to EPSG:3857
x, y = transformer.transform(location.latitude, location.longitude)
return x, y
else:
return None, None
except:
return None, None
# Iterate through the towns/cities in the 'Ort' column and get coordinates
for i, town in df['Ort'].items():
x, y = get_coordinates(town)
df.at[i, 'X'] = x
df.at[i, 'Y'] = y
# Save the updated dataframe to a new CSV
df.to_csv('combined_with_coordinates.csv', index=False)
print("Coordinates added and saved to combined_with_coordinates.csv")
The I added a new column called ‘Ideology’ and went through each entry and input ‘left’, ‘right’, or ‘islamist’ where the ideology of the attacker was clear. I then filtered the file to remove all rows with no value in the Ideology column.
This left me with 184 incidents since the year 2000.
Next was a tad more difficult. Many of the incidents labelled here as terror attacks are not what I would refer to as terrorism. Violence, yes, but not terrorism. So I want to here to differentiate between terrorism, political violence, and racist/antisemitic violence.
Terrorism is, for my purposes here, the use of violence to instill terror in a given population/group in order to create political or cultural/political change. So I will not be counting property destruction, individual racist attacks or political assassination. Violent these things may be, but their aim is not to instill terror in a population. I will however be including the murders carried out by the National Socialist Underground, as the purpose of those murders was to create terror within immigrant communities.
So, after going through and somewhat arbitrarily removing rows where the attack doesn’t meet my definition of terrorism I am left with 142 incidents. I will link to my data at the bottom of this piece.
Next I put together a Shiny app using R and upload it to shinyapps.io.
output$line_chart <- renderPlot({
# Create a vector of German month names
german_months <- c("Januar", "Februar", "März", "April", "Mai", "Juni",
"Juli", "August", "September", "Oktober", "November", "Dezember")
# Replace German month names with numerical equivalents in the date strings
for (i in seq_along(german_months)) {
terror$Datum.Beginn <- gsub(german_months[i], sprintf("%02d", i), terror$Datum.Beginn)
}
# Parse the date using lubridate, assuming the format is "dd mm yyyy"
terror$Datum.Beginn <- dmy(terror$Datum.Beginn)
terror$Year <- format(terror$Datum.Beginn, "%Y")
# Process data for line chart: group by year and ideology, and count the attacks
year_ideology_counts <- terror %>%
group_by(Year, Ideology) %>%
summarise(Count = n(), .groups = 'drop') %>%
filter(as.numeric(Year) >= 2000) # Filter data from the year 2000
ggplot(year_ideology_counts, aes(x = Year, y = Count, color = Ideology, group = Ideology)) +
geom_line(size = 1.2) +
geom_point(size = 3) + # Slightly larger points
scale_color_manual(values = c("left" = "red", "right" = "#8B4513", "islamist" = "black")) +
# Apply grey background and style the text with a black frame
theme(
panel.background = element_rect(fill = "white", color = NA), # White background inside the plot
plot.background = element_rect(fill = "white", color = NA), # White background around the plot
panel.border = element_rect(color = "black", fill = NA, size = 1.5), # Black border/frame
legend.position = "none", # Remove the legend
axis.text = element_text(size = 14, face = "bold"), # Larger and bold axis text
axis.title = element_text(size = 16, face = "bold"), # Larger and bold axis titles
plot.title = element_text(size = 18, face = "bold") # Larger and bold plot title
) +
labs(x = "Year", y = "Number of Attacks", title = "")
})
And if that all works, you should see an interactive map of Germany with all the terrorist attacks since the year 2000 which you can filter by right wing, left wing, or islamist. Then you should ask yourself, why the FDP want to ban foreigners from attending demonstrations and where the extremism is coming from…
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.
(and now we understand the title of this post)
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.
It’s almost like abstract art
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.
Doesn’t really *pop*, does it?
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.
(‘bemerkung’ being the column containing the data referring to which Flz is being recorded)
A simple model for the terminally lazy
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:
(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:
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”.
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.