Skip to content

Commit e1d4166

Browse files
committed
cosmetic corrections
1 parent 4576ab7 commit e1d4166

1 file changed

Lines changed: 29 additions & 17 deletions

File tree

vignettes/how-to.Rmd

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
title: "How to use this"
2+
title: "Density Plots for Dates"
33
output: rmarkdown::html_vignette
44
vignette: >
5-
%\VignetteIndexEntry{How to use this}
5+
%\VignetteIndexEntry{Density Plots for Dates}
66
%\VignetteEngine{knitr::rmarkdown}
77
%\VignetteEncoding{UTF-8}
88
bibliography: ../inst/literatur.bib
@@ -15,18 +15,25 @@ knitr::opts_chunk$set(
1515
fig.width = 7,
1616
fig.align = "center"
1717
)
18+
1819
library(knitr)
20+
library(ggplot2)
21+
plot_theme <- theme(panel.background = element_blank(),
22+
panel.grid.major = element_line(color = "grey60", linetype = "dashed"),
23+
panel.grid.minor = element_line(color = "grey80", linetype = "dashed"),
24+
legend.position = c(0.9,0.85), legend.background = element_rect(fill = "white", color = "grey60"))
25+
plot_fill <- scale_fill_manual(name="Technique", values = c("gray30", "tomato3"))
1926
```
2027

2128

22-
# Density Plots for Dates
29+
## Why?
2330

2431
A rather common problem in archaeology is the fuzziness of dates assigned to objects. If one wants to visualize overall changes in - let's say - pottery consumption, bar charts often fall short in that regard. If we have Phases a -- f, then some of the objects can usually be dated to a, c, and f, as an example, but others will by classified as "a to c" or "b to c". But how can these data still be used for examining changes in a large set of objects?
2532

2633
First, it is handy to translate the phases into numbers, for which we should conveniently choose the 'actual' dating. This may cause other problems in the end, since such phases are often employed to avoid dates, but it is necessary as the aim is to visualize the distribution on a continuous scale, for which numbers are needed. Also, this step may be reversed for the final visualization but supplementing or replacing the scale on the x-axis with the respective phases.
2734
Ideally, one can produce a 'beginning' and 'end' date for each object, or let's say an earliest possible dating and a latest possible dating, e.g. corresponding to beginning and start of each phase the object is dated to.
2835

29-
To show and explain how this would work, I chose a random sample of athenian pottery from the beazley archive ([@BAPD]), as it is a large publicly available dataset. (Since the format provided by the BAPD is slightly different from that needed here I converted the data beforehand to match my requirements. No values have been changed.)
36+
To show and explain how this would work, I chose a random sample of athenian pottery from the beazley archive ([@BAPD]), as it is a large publicly available dataset. (Since the format provided by the BAPD is slightly different from that needed here I converted the data beforehand to match my requirements. No values have been changed. The sample dataset is included in datplot.)
3037

3138
```{r prep}
3239
library(datplot)
@@ -48,18 +55,27 @@ This method will not be useful for dating specific context, since any concept of
4855
Other approaches, e.g. using the median date of each object, may often produce similar outcomes, but create other problems. A lot of information is lost on the way when employing averaged or median data, as large amount of loosely dated objects will produce peaks at unreasonable values. (Consider a large amount of objects dated between 600 and 400 BCE all attributed to the year 500 BCE.)
4956

5057
```{r barplot}
51-
counts <- Beazley
52-
counts$DAT_mean <- ((counts$DAT_max + counts$DAT_min) / 2)
53-
counts <- table(counts$DAT_mean)
54-
plot(counts)
58+
Beazley$DAT_mean <- (Beazley$DAT_max + Beazley$DAT_min) / 2
59+
library(ggplot2)
60+
ggplot(Beazley, aes(x = DAT_mean, fill = Technique)) +
61+
geom_histogram() + plot_theme + plot_fill
5562
```
5663

5764
Employing dating steps will even out unreasonable peaks. Not especially the gap between -425 and -300 in the plot above, that is -- in the plot below -- filled with a constant amount of objects in each year. This is due to the data containing large amounts of objects dating from -400 to -300 BCE. Of couse, due to duplicating each object numerous times (see table below), the counts represented on the y-axis have become meaningless.
5865

59-
```{r steps}
66+
```{r steps1}
6067
library(datplot)
6168
result <- datsteps(Beazley, stepsize = 5)
62-
hist(result$DAT_step)
69+
ggplot(result, aes(x = DAT_step, fill = variable)) +
70+
geom_histogram() + plot_theme + plot_fill
71+
```
72+
73+
`datsteps()` can also calculate a stepsize on its own. It equals the closest possible dating of any object.
74+
75+
```{r steps2}
76+
result <- datsteps(Beazley, stepsize = "auto")
77+
ggplot(result, aes(x = DAT_step, fill = variable)) +
78+
geom_histogram() + plot_theme + plot_fill
6379
```
6480

6581

@@ -70,6 +86,7 @@ kable(head(result))
7086
Due to the impossibility of displaying object counts as well, it is ideal to use kernel density estimates for visualization. The density plot below shows the result. The peak at around -500 indicates that is area has the highest overlay, so a large part of the objects in our sample have been dated around this time. The same distribution can also be seen in the bar plots above. This, however, is not yet very informative.
7187

7288
```{r density one}
89+
result <- datsteps(Beazley, stepsize = 25)
7390
dens <- result
7491
dens$weight <- (dens$weight / sum(dens$weight))
7592
dens <- density(x = dens$DAT_step, weights = dens$weight)
@@ -98,25 +115,20 @@ kable(head(result))
98115
In the case of the beazley archives data [@BAPD] we can clearly see what we knew before: Black-figure pottery is older than red-figure pottery. (The data are from a random sample of athenian pottery from the beazley archive, n = 1000. Computation of the dating steps may not work with very, very large datasets, or simply take up a lot of time.)
99116

100117
```{r ggplot, warning=FALSE}
101-
library(ggplot2)
102118
ggplot(data = result, aes(x = DAT_step,
103-
color = variable,
104119
fill = variable)) +
105120
geom_density(aes(weight = weight), alpha = 0.5) +
106-
xlab("Dating") +
107-
theme(panel.background = element_blank())
121+
xlab("Dating") + plot_theme + plot_fill
108122
```
109123

110124

111125
Please note that the plot does change when the weights are omitted (see plot below). When every step is valued equally, a lot of steps fall into the end of the 4th century (as mentioned above), since they were dated as e.g. "-400 to -300".
112126

113127
```{r ggplot without weight, warning=FALSE}
114128
ggplot(data = result, aes(x = DAT_step,
115-
color = variable,
116129
fill = variable)) +
117130
geom_density(alpha = 0.5) +
118-
xlab("Dating") +
119-
theme(panel.background = element_blank())
131+
xlab("Dating") + plot_theme + plot_fill
120132
```
121133

122134

0 commit comments

Comments
 (0)