|
| 1 | +--- |
| 2 | +title: "How to use this" |
| 3 | +output: rmarkdown::html_vignette |
| 4 | +vignette: > |
| 5 | + %\VignetteIndexEntry{How to use this} |
| 6 | + %\VignetteEngine{knitr::rmarkdown} |
| 7 | + %\VignetteEncoding{UTF-8} |
| 8 | +bibliography: ../inst/literatur.bib |
| 9 | +--- |
| 10 | + |
| 11 | +```{r, include = FALSE} |
| 12 | +knitr::opts_chunk$set( |
| 13 | + collapse = TRUE, |
| 14 | + comment = "#>", |
| 15 | + fig.width = 7, |
| 16 | + fig.align = "center" |
| 17 | +) |
| 18 | +library(knitr) |
| 19 | +``` |
| 20 | + |
| 21 | + |
| 22 | +# Density Plots for Dates |
| 23 | + |
| 24 | +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? |
| 25 | + |
| 26 | +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. |
| 27 | +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. |
| 28 | + |
| 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.) |
| 30 | + |
| 31 | +```{r prep} |
| 32 | +library(datplot) |
| 33 | +data(Beazley) |
| 34 | +``` |
| 35 | +```{r preptable, echo = FALSE} |
| 36 | +kable(Beazley[sample(1:nrow(Beazley), 10, replace = FALSE),]) |
| 37 | +``` |
| 38 | + |
| 39 | +## How to display a range? |
| 40 | + |
| 41 | +The table provides two dates for each object. The earliest possible dating (DAT_min) and the latest possible dating (DAT_max). In order to be able to process this to a [density graph](https://en.wikipedia.org/wiki/Kernel_density_estimation), which is the most elegant means of visualization for continuous distributions. (At least if the goal is merely to evaluate changes over time and not to look at actual objects counts, which will be omitted.) |
| 42 | + |
| 43 | +Objects that can be dated with greater confidence should have a larger impact on the overall visualisation. The core function of this package (`datsteps()`) produces a column named 'weight' which contains a value that corresponds to one (as the closest possible dating of one year) devided by the timespan between the two dating variables. The greater the timespan, the lower the weight value. |
| 44 | +Secondly, every object is duplicated a number of times equal to the dating range devided by the stepsize-variable. Each duplicate has its own 'date', one single value between the two extremes. The above mention weight variable is devided by the number of steps, so that each new fictional object or 'date step' counts only as a fraction of the actual object. |
| 45 | + |
| 46 | +This method will not be useful for dating specific context, since any concept of _terminus post/ante quem_ is lost here, which is important on a smaller scale. For the visualization of changes in _trends_ over time, e.g. the popularity of pottery types, or overall peaks in occupation from survey data, the method is ideal. |
| 47 | + |
| 48 | +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.) |
| 49 | + |
| 50 | +```{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) |
| 55 | +``` |
| 56 | + |
| 57 | +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. |
| 58 | + |
| 59 | +```{r steps} |
| 60 | +library(datplot) |
| 61 | +result <- datsteps(Beazley, stepsize = 5) |
| 62 | +hist(result$DAT_step) |
| 63 | +``` |
| 64 | + |
| 65 | + |
| 66 | +```{r stepstable, echo = FALSE} |
| 67 | +kable(head(result)) |
| 68 | +``` |
| 69 | + |
| 70 | +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. |
| 71 | + |
| 72 | +```{r density one} |
| 73 | +dens <- result |
| 74 | +dens$weight <- (dens$weight / sum(dens$weight)) |
| 75 | +dens <- density(x = dens$DAT_step, weights = dens$weight) |
| 76 | +plot(dens) |
| 77 | +``` |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | +## Scaling the weight along groups of objects |
| 82 | + |
| 83 | +In order to display the objects seperated into groups, the weights first have to be scaled along group membership, so that the sum of all weights in a group will equal 1. datplots function `scaleweight()` does exactly that for a dataframe as it was returned by `datsteps()`. A column that contains the variables for group membership needs to indicated. |
| 84 | + |
| 85 | + |
| 86 | +```{r scaleweight} |
| 87 | +result <- scaleweight(result, 2) |
| 88 | +``` |
| 89 | + |
| 90 | +```{r scaleweighttable, echo = FALSE} |
| 91 | +kable(head(result)) |
| 92 | +``` |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | +## Plots for the distribution of objects across time |
| 97 | + |
| 98 | +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.) |
| 99 | + |
| 100 | +```{r ggplot, warning=FALSE} |
| 101 | +library(ggplot2) |
| 102 | +ggplot(data = result, aes(x = DAT_step, |
| 103 | + color = variable, |
| 104 | + fill = variable)) + |
| 105 | + geom_density(aes(weight = weight), alpha = 0.5) + |
| 106 | + xlab("Dating") + |
| 107 | + theme(panel.background = element_blank()) |
| 108 | +``` |
| 109 | + |
| 110 | + |
| 111 | +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". |
| 112 | + |
| 113 | +```{r ggplot without weight, warning=FALSE} |
| 114 | +ggplot(data = result, aes(x = DAT_step, |
| 115 | + color = variable, |
| 116 | + fill = variable)) + |
| 117 | + geom_density(alpha = 0.5) + |
| 118 | + xlab("Dating") + |
| 119 | + theme(panel.background = element_blank()) |
| 120 | +``` |
| 121 | + |
| 122 | + |
| 123 | +The smooth curves of kernel density estimates are a more realistic approach to dating. The production of objects was as continuous as their use, so it seems only reasonable to display it in a continuous fashion. |
| 124 | + |
| 125 | + |
| 126 | +## References |
| 127 | + |
0 commit comments