Skip to content

Commit 118d6dc

Browse files
committed
merge
Merge branch 'packagedoc' of https://github.com/lsteinmann/datplot into packagedoc # Conflicts: # vignettes/data_preparation.Rmd
2 parents 5057755 + bc67950 commit 118d6dc

35 files changed

Lines changed: 3555 additions & 122 deletions

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
^.*\.Rproj$
22
^\.Rproj\.user$
33
^\.github$
4+
^data-raw$
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Screenshots**
24+
If applicable, add screenshots to help explain your problem.
25+
26+
**Desktop (please complete the following information):**
27+
- OS: [e.g. iOS]
28+
- Browser [e.g. chrome, safari]
29+
- Version [e.g. 22]
30+
31+
**Smartphone (please complete the following information):**
32+
- Device: [e.g. iPhone6]
33+
- OS: [e.g. iOS8.1]
34+
- Browser [e.g. stock browser, safari]
35+
- Version [e.g. 22]
36+
37+
**Additional context**
38+
Add any other context about the problem here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

.github/workflows/R-CMD-check.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ on:
22
push:
33
branches:
44
- master
5+
- inscrbithynia
56
pull_request:
67
branches:
78
- master

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r
2+
3+
language: R
4+
cache: packages
5+
6+
7+
r_packages:
8+
- covr
9+
10+
after_success:
11+
- Rscript -e 'library(covr); codecov()'

DESCRIPTION

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
Package: datplot
22
Type: Package
33
Title: Preparation of object dating ranges for density plots
4-
Version: 0.2.2
4+
Version: 0.2.3
55
Author: Lisa Steinmann
66
Maintainer: Lisa Steinmann <lisa.steinmann@rub.de>
77
Description: Converting date ranges into dating 'steps' eases the visualization of changes in e.g. pottery consumption, style and other variables over time. This package provides tools to process and prepare data for visualization.
88
License: CC BY-SA 4.0
99
Encoding: UTF-8
1010
LazyData: true
11-
RoxygenNote: 7.1.0
11+
RoxygenNote: 7.1.1
1212
Suggests:
1313
testthat,
1414
devtools,
1515
knitr,
1616
rmarkdown,
17-
ggplot2
17+
tidyverse,
18+
ggplot2,
19+
ggridges,
20+
readxl,
21+
reshape2,
22+
covr
1823
Depends:
1924
R (>= 2.10)
2025
VignetteBuilder: knitr

R/data.R

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#' \item ID. Identifier of the Objects (has to be unique)
88
#' \item var. Grouping variable, such as a Type or a Findspot
99
#' \item DAT_min. Integer: lower range of the dating, BCE in negative numbers
10-
#' \item DAT_max. Integer: uppder range of the dating, BCE in negative numbers
10+
#' \item DAT_max. Integer: upper range of the dating, BCE in negative numbers
1111
#' }
1212
#'
1313
#' @docType data
@@ -30,7 +30,7 @@ NULL
3030
#' \item Identifier (Vase.Number in BAPD)
3131
#' \item Technique: Sample contains only red- or blackfigured objects
3232
#' \item DAT_min. Integer: lower range of the dating, BCE in negative numbers
33-
#' \item DAT_max. Integer: uppder range of the dating, BCE in negative numbers
33+
#' \item DAT_max. Integer: upper range of the dating, BCE in negative numbers
3434
#' }
3535
#'
3636
#' @docType data
@@ -42,3 +42,25 @@ NULL
4242

4343
"Beazley"
4444
NULL
45+
46+
47+
#' @title Inscr_Bithynia
48+
#' @description The data set was gathered by Barbora Weissov\'a and published as part
49+
#' of her dissertation “Regional Economy, Settlement Patterns and the Road System in
50+
#' Bithynia (4th Century BC - 6th Century AD). Spatial and Quantitative Analysis.”.
51+
#'
52+
#'
53+
#' @format A data frame with 2878 rows and 9 variables:
54+
#' \describe{
55+
#' \item{\code{ID}}{character COLUMN_DESCRIPTION}
56+
#' \item{\code{ikey}}{character ID at \url{https://inscriptions.packhum.org/}, if available}
57+
#' \item{\code{Location}}{factor Findspot of the Inscription (City)}
58+
#' \item{\code{Source}}{character Corpus/Citation of the Inscription}
59+
#' \item{\code{Dating}}{character Original Chronological Assesment, may contain inconsistencies}
60+
#' \item{\code{Language}}{factor Language of the Inscription, can either be Latin, Greek, or both}
61+
#' \item{\code{uncertain_dating}}{logical TRUE if Dating is not certain, FALSE if dating is certain}
62+
#' \item{\code{DAT_min}}{integer lower border of the dating timespan, negative values for BCE, positive values for CE}
63+
#' \item{\code{DAT_max}}{integer uppper border of the dating timespan, negative values for BCE, positive values for CE}
64+
#'}
65+
#' @source Weissová, Barbora. 2019. “Regional Economy, Settlement Patterns and the Road System in Bithynia (4th Century BC - 6th Century AD). Spatial and Quantitative Analysis.” Dissertation, Berlin: Freie Universität Berlin. \url{https://refubium.fu-berlin.de/handle/fub188/23730}, partially after \url{https://inscriptions.packhum.org/}
66+
"Inscr_Bithynia"

R/datplot_utility.R

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ get.step.sequence <- function(datmin = 0, datmax = 100, stepsize = 25) {
130130
if (timespan > (stepsize*0.6)) {
131131
# If the timespan exceeds 60% of the stepsize, three steps will be created corresponding to minimum, mean and maximum dating
132132
sequence <- c(datmin, round(((datmin+datmax)/2), digits = 0), datmax)
133+
} else if (timespan == 0) {
134+
# for objects dated to one year, only use one year!
135+
sequence <- datmin
133136
} else {
134137
# if the timespan is less than 60% of the stepsize, just two values corresponding to minimum and maximum dating will be returned
135138
sequence <- c(datmin, datmax)
@@ -142,7 +145,7 @@ get.step.sequence <- function(datmin = 0, datmax = 100, stepsize = 25) {
142145
if (resid >= (stepsize/2)) {
143146
# if the residual is larger or equals half the stepsize, the stepsize is temporarily modified to fit the as many values
144147
# as it would with the length of the sequence generated
145-
stepsize_mod <- (datmax-datmin)/length(sequence)
148+
stepsize_mod <- (datmax-datmin)/(length(sequence)+1) ## length(sequence + 1 might be better!)
146149
sequence <- seq(datmin, datmax, stepsize_mod)
147150
# then rounds all values except first and last, which need to stay as minumum and maximum date
148151
sequence[-c(1,length(sequence))] <- round(sequence[-c(1,length(sequence))], digits = 0)
@@ -203,17 +206,14 @@ create.sub.objects <- function(DAT_mat, stepsize) {
203206
for (i in 1:nrow(DAT_mat)) {
204207
sequence <- NULL
205208
sequence <- get.step.sequence(DAT_mat[i,"datmin"], DAT_mat[i,"datmax"], stepsize)
206-
for (step in sequence) {
207-
wip <- as.vector(DAT_mat[i,])
208-
wip[5] <- step
209-
wip[4] <- wip[4] #/ length(sequence)
210-
first_na <- match(NA, result[,1])
211-
result[first_na,1] <- wip[1]
212-
result[first_na,3] <- wip[2]
213-
result[first_na,4] <- wip[3]
214-
result[first_na,5] <- wip[4]
215-
result[first_na,6] <- wip[5]
216-
}
209+
210+
first_na <- match(NA, result[,1])
211+
last_row <- first_na + (length(sequence)-1)
212+
result[first_na:last_row,1] <- DAT_mat[i,1]
213+
result[first_na:last_row,3] <- DAT_mat[i,2]
214+
result[first_na:last_row,4] <- DAT_mat[i,3]
215+
result[first_na:last_row,5] <- DAT_mat[i,4]
216+
result[first_na:last_row,6] <- sequence
217217
}
218218
result <- result[-c(match(NA, result[,1]):nrow(result)), ]
219219
return(result)
@@ -231,13 +231,8 @@ create.sub.objects <- function(DAT_mat, stepsize) {
231231

232232

233233
check.number <- function(value) {
234-
result <- is.integer(value)
235-
if (result == FALSE) {
236-
result <- is.numeric(value)
237-
if (result == FALSE) {
238-
result <- is.double(value)
239-
}
240-
}
234+
result <- c(is.integer(value), is.numeric(value), is.double(value))
235+
result <- any(result)
241236
return(result)
242237
}
243238

@@ -256,15 +251,16 @@ check.structure <- function(DAT_df) {
256251
names(dat_df_structure) <- c("is.df", "is.id", "is.var", "is.minDAT", "is.maxDAT")
257252

258253
dat_df_structure["is.df"] <- is.data.frame(DAT_df)
259-
dat_df_structure["is.id"] <- is.character(DAT_df[,1])
260-
dat_df_structure["is.var"] <- is.factor(DAT_df[,2])
261-
dat_df_structure[c("is.minDAT", "is.maxDAT")] <- c(check.number(DAT_df[,3]), check.number(DAT_df[,4]))
254+
dat_df_structure["is.id"] <- is.character(DAT_df[,1, drop = TRUE])
255+
dat_df_structure["is.var"] <- is.factor(DAT_df[,2, drop = TRUE])
256+
dat_df_structure[c("is.minDAT", "is.maxDAT")] <- c(check.number(DAT_df[,3, drop = TRUE]),
257+
check.number(DAT_df[,4, drop = TRUE]))
262258

263259
if (dat_df_structure[1] == FALSE) {
264260
result <- FALSE
265261
stop("datsteps requires an object of class data.frame")
266262
} else { result <- TRUE }
267-
if (any(dat_df_structure[4:5] == FALSE)) {
263+
if (any(dat_df_structure[c("is.minDAT", "is.maxDAT")] == FALSE)) {
268264
result <- FALSE
269265
stop("The 3rd or 4th columns of your data.frame are not numbers.")
270266
} else { result <- TRUE }

R/datsteps.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#' @export datsteps
1919

2020
datsteps <- function(DAT_df, stepsize = 25) {
21-
21+
DAT_df <- as.data.frame(DAT_df)
2222
# Checking the overall structure
2323
check.structure(DAT_df)
2424

R/get.histogramscale.R

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
11
#' @title Scaling Factor for Combined Histogramm Plots
22
#'
3-
#' @description Requires a dataframe as produced by datsteps().
4-
#' Meaning 6 columns in the following order:
5-
#' * ID,
6-
#' * group,
7-
#' * minimum/earliest date,
8-
#' * maximum/latest date,
9-
#' * weight,
10-
#' * 'DAT_Steps'
3+
#' @description Requires a dataframe as produced by datsteps() or a number as DAT_df_steps. Calculated the value with which the
4+
#' y-axis of a density graph should be multplied in order to be visible in the corresponding histogram.
115
#'
12-
#' @param DAT_df a dataframe as returned by datsteps
13-
#' @param bw the bandwidth to use for the density function and histogram. Should be stepsize used to
14-
#' create the dataframe. If a df as returned by datsteps() is given, stepsize is automatically assigned
15-
#' using the corresponding attribute.
6+
#' @param DAT_df_steps a dataframe as returned by datsteps
7+
#' @param binwidth the bandwidth to use for the density function and histogram. Should be stepsize used to
8+
#' create the dataframe. If a df as returned by datsteps() is given, stepsize can be automatically assigned
9+
#' using the corresponding attribute (binwidth = "stepsize")
1610
#'
1711
#' @return the value with which to scale the density curve to a histogram plot so that both will be visible
1812
#'
1913
#' @examples
2014
#' DAT_df_steps <- datsteps(DAT_df[1:100,], stepsize = 25)
2115
#' get.histogramscale(DAT_df_steps)
2216
#'
17+
#' get.histogramscale(500, binwidth = 20)
18+
#'
2319
#' @export get.histogramscale
2420

25-
get.histogramscale <- function(DAT_df, bw = "auto") {
26-
if (bw == "auto") {
27-
if (!is.null(attributes(DAT_df)$stepsize)) {
28-
bw <- attributes(DAT_df)$stepsize
29-
} else {
30-
stop("Either specify stepsize/bandwidth (bw = ) or use a data.frame as returned by datsteps()")
21+
get.histogramscale <- function(DAT_df_steps, binwidth = "stepsize") {
22+
if (check.number(DAT_df_steps)) {
23+
nrow <- DAT_df_steps
24+
if (binwidth == "stepsize") {
25+
stop("'binwidth == stepsize' cannot be used with a number, supply either a dataframe as returned by datsteps or a numerical bindwidth")
26+
}
27+
} else {
28+
nrow <- nrow(DAT_df_steps)
29+
if (binwidth == "stepsize") {
30+
binwidth <- attributes(DAT_df_steps)$stepsize
31+
if (is.null(binwidth)) {
32+
stop("Supply numerical binwidth or dataframe as returned by datsteps")
33+
}
34+
} else if (!check.number(binwidth)) {
35+
stop('Supply numerical binwidth or use binwidth = "stepsize".')
3136
}
32-
} else if (!is.numeric(bw)) {
33-
stop("Either specify stepsize/bandwidth (bw = ) or use a data.frame as returned by datsteps()")
3437
}
35-
density <- density(DAT_df$DAT_step, weights = DAT_df$weight, bw = bw)
36-
breaks <- range(DAT_df$DAT_step)
37-
breaks <- breaks[2] - breaks [1]
38-
breaks <- round(breaks / bw, digits = 0)
39-
hist <- hist(DAT_df$DAT_step, breaks = breaks)
40-
histogramscale <- max(hist$counts) / max(density$y)
38+
histogramscale <- nrow * binwidth
4139
return(histogramscale)
4240
}

0 commit comments

Comments
 (0)