Skip to content

Commit 8c3adf8

Browse files
committed
updated vignette to show get.histogramscale() as well
1 parent 7eef9a5 commit 8c3adf8

1 file changed

Lines changed: 26 additions & 9 deletions

File tree

vignettes/how-to.Rmd

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Other approaches, e.g. using the median date of each object, may often produce s
5959
Beazley$DAT_mean <- (Beazley$DAT_max + Beazley$DAT_min) / 2
6060
library(ggplot2)
6161
ggplot(Beazley, aes(x = DAT_mean, fill = Technique)) +
62-
geom_histogram() + plot_theme + plot_fill
62+
geom_histogram(binwidth = 25, position = "dodge") + plot_theme + plot_fill
6363
```
6464

6565
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.
@@ -68,15 +68,15 @@ Employing dating steps will even out unreasonable peaks. Not especially the gap
6868
library(datplot)
6969
result <- datsteps(Beazley, stepsize = 5)
7070
ggplot(result, aes(x = DAT_step, fill = variable)) +
71-
geom_histogram() + plot_theme + plot_fill
71+
geom_histogram(binwidth = 25, position = "dodge") + plot_theme + plot_fill
7272
```
7373

7474
`datsteps()` can also calculate a stepsize on its own. It equals the closest possible dating of any object.
7575

7676
```{r steps2}
7777
result <- datsteps(Beazley, stepsize = "auto")
7878
ggplot(result, aes(x = DAT_step, fill = variable)) +
79-
geom_histogram() + plot_theme + plot_fill
79+
geom_histogram(binwidth = 25, position = "dodge") + plot_theme + plot_fill
8080
```
8181

8282

@@ -89,7 +89,7 @@ Due to the impossibility of displaying object counts as well, it is ideal to use
8989
```{r density one}
9090
result <- datsteps(Beazley, stepsize = 25)
9191
dens <- result
92-
dens$weight <- (dens$weight / sum(dens$weight))
92+
dens <- scaleweight(result, var = "all")
9393
dens <- density(x = dens$DAT_step, weights = dens$weight)
9494
plot(dens)
9595
```
@@ -102,7 +102,7 @@ In order to display the objects seperated into groups, the weights first have to
102102

103103

104104
```{r scaleweight}
105-
result <- scaleweight(result, 2)
105+
result <- scaleweight(result, var = 2)
106106
```
107107

108108
```{r scaleweighttable, echo = FALSE}
@@ -117,13 +117,14 @@ In the case of the beazley archives data [@BAPD] we can clearly see what we knew
117117

118118
```{r ggplot, warning=FALSE}
119119
ggplot(data = result, aes(x = DAT_step,
120-
fill = variable)) +
121-
geom_density(aes(weight = weight), alpha = 0.5) +
120+
fill = variable,
121+
weight = weight)) +
122+
geom_density(alpha = 0.5) +
122123
xlab("Dating") + plot_theme + plot_fill
123124
```
124125

125126

126-
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".
127+
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". The impact here is not very huge, as the dating ranges of the objects do not vary greatly. However, the differences can be very dramatic for more heterogenious data.
127128

128129
```{r ggplot without weight, warning=FALSE}
129130
ggplot(data = result, aes(x = DAT_step,
@@ -132,8 +133,24 @@ ggplot(data = result, aes(x = DAT_step,
132133
xlab("Dating") + plot_theme + plot_fill
133134
```
134135

136+
We also added a function that calculated the value needed to scale the density curve to the axis of a Histogram of the dating steps. Please note that the histogram will not show the actual objects counts, but the counts of the maximum possible objects dated to the corresponding year resp. bin. The value to scale the density curve for a combined plot with a histogram can be obtained via `get.histogramscale`:
137+
138+
139+
```{r histogramscale, warning = FALSE, message = FALSE}
140+
histogramscale <- get.histogramscale(result)
141+
```
142+
143+
144+
```{r ggplot-combination}
145+
ggplot(result, aes(x = DAT_step, fill = variable)) +
146+
stat_density(alpha = 0.5, position = "dodge", aes(y = (..density..*histogramscale), weight = weight ))+
147+
geom_histogram(alpha = 0.5, binwidth = 25, position = "dodge") + plot_theme + plot_fill +
148+
labs(y = "maximum number of objects per year", x = "Dating")
149+
```
150+
151+
The combination of density curve and histogram also shows the common problem of histograms. Their output depends significantly on where the first bin is placed and may show a skewed distribution especially for roughly dated objects.
135152

136-
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.
153+
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 more continuous fashion on a flexible timescale.
137154

138155

139156
## References

0 commit comments

Comments
 (0)