Paketmanagement mit packcrat.

This commit is contained in:
daniel 2019-01-02 07:37:05 +01:00
parent 00670d9dc1
commit f2ae692432
8 changed files with 739 additions and 24 deletions

3
.Rprofile Normal file
View File

@ -0,0 +1,3 @@
#### -- Packrat Autoloader (version 0.5.0) -- ####
source("packrat/init.R")
#### -- End Packrat Autoloader -- ####

2
.gitignore vendored
View File

@ -7,3 +7,5 @@
*.pptx
*-figure/
*-files/
packrat/lib*/
packrat/src/

18
README.md Normal file
View File

@ -0,0 +1,18 @@
Vorhofkatheter-Statistik
========================
Statistische Auswertung der Vorhofkatheter-Datenbank.
Man benötigt:
* [R](https://www.r-project.org)
* [packrat](http://rstudio.github.io/packrat/)
Die Datei `vhk.csv` wird von der Abfrage `qryExportToCsv` generiert.
Es gibt kein traditionelles R-Skript, sondern eine R-Markdown-Datei,
die den Code zum Erzeugen der Abbildungen enthält. Als Präsentationsformat
eignen sich HTML mit Slidy und PDF am besten. HTML mit ioslides kann vom
in der Klinik immer noch installierten Internet Explorer nicht dargestellt
werden, und der PowerPoint-Export klappt auch nicht so gut (Stand 1/2019).

View File

@ -14,3 +14,5 @@ LaTeX: pdfLaTeX
AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
BuildType: Makefile

226
packrat/init.R Normal file
View File

@ -0,0 +1,226 @@
local({
## Helper function to get the path to the library directory for a
## given packrat project.
getPackratLibDir <- function(projDir = NULL) {
path <- file.path("packrat", "lib", R.version$platform, getRversion())
if (!is.null(projDir)) {
## Strip trailing slashes if necessary
projDir <- sub("/+$", "", projDir)
## Only prepend path if different from current working dir
if (!identical(normalizePath(projDir), normalizePath(getwd())))
path <- file.path(projDir, path)
}
path
}
## Ensure that we set the packrat library directory relative to the
## project directory. Normally, this should be the working directory,
## but we also use '.rs.getProjectDirectory()' if necessary (e.g. we're
## rebuilding a project while within a separate directory)
libDir <- if (exists(".rs.getProjectDirectory"))
getPackratLibDir(.rs.getProjectDirectory())
else
getPackratLibDir()
## Unload packrat in case it's loaded -- this ensures packrat _must_ be
## loaded from the private library. Note that `requireNamespace` will
## succeed if the package is already loaded, regardless of lib.loc!
if ("packrat" %in% loadedNamespaces())
try(unloadNamespace("packrat"), silent = TRUE)
if (suppressWarnings(requireNamespace("packrat", quietly = TRUE, lib.loc = libDir))) {
# Check 'print.banner.on.startup' -- when NA and RStudio, don't print
print.banner <- packrat::get_opts("print.banner.on.startup")
if (print.banner == "auto" && is.na(Sys.getenv("RSTUDIO", unset = NA))) {
print.banner <- TRUE
} else {
print.banner <- FALSE
}
return(packrat::on(print.banner = print.banner))
}
## Escape hatch to allow RStudio to handle bootstrapping. This
## enables RStudio to provide print output when automagically
## restoring a project from a bundle on load.
if (!is.na(Sys.getenv("RSTUDIO", unset = NA)) &&
is.na(Sys.getenv("RSTUDIO_PACKRAT_BOOTSTRAP", unset = NA))) {
Sys.setenv("RSTUDIO_PACKRAT_BOOTSTRAP" = "1")
setHook("rstudio.sessionInit", function(...) {
# Ensure that, on sourcing 'packrat/init.R', we are
# within the project root directory
if (exists(".rs.getProjectDirectory")) {
owd <- getwd()
setwd(.rs.getProjectDirectory())
on.exit(setwd(owd), add = TRUE)
}
source("packrat/init.R")
})
return(invisible(NULL))
}
## Bootstrapping -- only performed in interactive contexts,
## or when explicitly asked for on the command line
if (interactive() || "--bootstrap-packrat" %in% commandArgs(TRUE)) {
needsRestore <- "--bootstrap-packrat" %in% commandArgs(TRUE)
message("Packrat is not installed in the local library -- ",
"attempting to bootstrap an installation...")
## We need utils for the following to succeed -- there are calls to functions
## in 'restore' that are contained within utils. utils gets loaded at the
## end of start-up anyhow, so this should be fine
library("utils", character.only = TRUE)
## Install packrat into local project library
packratSrcPath <- list.files(full.names = TRUE,
file.path("packrat", "src", "packrat")
)
## No packrat tarballs available locally -- try some other means of installation
if (!length(packratSrcPath)) {
message("> No source tarball of packrat available locally")
## There are no packrat sources available -- try using a version of
## packrat installed in the user library to bootstrap
if (requireNamespace("packrat", quietly = TRUE) && packageVersion("packrat") >= "0.2.0.99") {
message("> Using user-library packrat (",
packageVersion("packrat"),
") to bootstrap this project")
}
## Couldn't find a user-local packrat -- try finding and using devtools
## to install
else if (requireNamespace("devtools", quietly = TRUE)) {
message("> Attempting to use devtools::install_github to install ",
"a temporary version of packrat")
library(stats) ## for setNames
devtools::install_github("rstudio/packrat")
}
## Try downloading packrat from CRAN if available
else if ("packrat" %in% rownames(available.packages())) {
message("> Installing packrat from CRAN")
install.packages("packrat")
}
## Fail -- couldn't find an appropriate means of installing packrat
else {
stop("Could not automatically bootstrap packrat -- try running ",
"\"'install.packages('devtools'); devtools::install_github('rstudio/packrat')\"",
"and restarting R to bootstrap packrat.")
}
# Restore the project, unload the temporary packrat, and load the private packrat
if (needsRestore)
packrat::restore(prompt = FALSE, restart = TRUE)
## This code path only reached if we didn't restart earlier
unloadNamespace("packrat")
requireNamespace("packrat", lib.loc = libDir, quietly = TRUE)
return(packrat::on())
}
## Multiple packrat tarballs available locally -- try to choose one
## TODO: read lock file and infer most appropriate from there; low priority because
## after bootstrapping packrat a restore should do the right thing
if (length(packratSrcPath) > 1) {
warning("Multiple versions of packrat available in the source directory;",
"using packrat source:\n- ", shQuote(packratSrcPath))
packratSrcPath <- packratSrcPath[[1]]
}
lib <- file.path("packrat", "lib", R.version$platform, getRversion())
if (!file.exists(lib)) {
dir.create(lib, recursive = TRUE)
}
message("> Installing packrat into project private library:")
message("- ", shQuote(lib))
surround <- function(x, with) {
if (!length(x)) return(character())
paste0(with, x, with)
}
## Invoke install.packages() in clean R session
peq <- function(x, y) paste(x, y, sep = " = ")
installArgs <- c(
peq("pkgs", surround(packratSrcPath, with = "'")),
peq("lib", surround(lib, with = "'")),
peq("repos", "NULL"),
peq("type", surround("source", with = "'"))
)
fmt <- "utils::install.packages(%s)"
installCmd <- sprintf(fmt, paste(installArgs, collapse = ", "))
## Write script to file (avoid issues with command line quoting
## on R 3.4.3)
installFile <- tempfile("packrat-bootstrap", fileext = ".R")
writeLines(installCmd, con = installFile)
on.exit(unlink(installFile), add = TRUE)
fullCmd <- paste(
surround(file.path(R.home("bin"), "R"), with = "\""),
"--vanilla",
"--slave",
"-f",
surround(installFile, with = "\"")
)
system(fullCmd)
## Tag the installed packrat so we know it's managed by packrat
## TODO: should this be taking information from the lockfile? this is a bit awkward
## because we're taking an un-annotated packrat source tarball and simply assuming it's now
## an 'installed from source' version
## -- InstallAgent -- ##
installAgent <- "InstallAgent: packrat 0.5.0"
## -- InstallSource -- ##
installSource <- "InstallSource: source"
packratDescPath <- file.path(lib, "packrat", "DESCRIPTION")
DESCRIPTION <- readLines(packratDescPath)
DESCRIPTION <- c(DESCRIPTION, installAgent, installSource)
cat(DESCRIPTION, file = packratDescPath, sep = "\n")
# Otherwise, continue on as normal
message("> Attaching packrat")
library("packrat", character.only = TRUE, lib.loc = lib)
message("> Restoring library")
if (needsRestore)
packrat::restore(prompt = FALSE, restart = FALSE)
# If the environment allows us to restart, do so with a call to restore
restart <- getOption("restart")
if (!is.null(restart)) {
message("> Packrat bootstrap successfully completed. ",
"Restarting R and entering packrat mode...")
return(restart())
}
# Callers (source-erers) can define this hidden variable to make sure we don't enter packrat mode
# Primarily useful for testing
if (!exists(".__DONT_ENTER_PACKRAT_MODE__.") && interactive()) {
message("> Packrat bootstrap successfully completed. Entering packrat mode...")
packrat::on()
}
Sys.unsetenv("RSTUDIO_PACKRAT_BOOTSTRAP")
}
})

453
packrat/packrat.lock Normal file
View File

@ -0,0 +1,453 @@
PackratFormat: 1.4
PackratVersion: 0.5.0
RVersion: 3.5.2
Repos: CRAN=https://cloud.r-project.org
Package: BH
Source: CRAN
Version: 1.66.0-1
Hash: 4cc8883584b955ed01f38f68bc03af6d
Package: DBI
Source: CRAN
Version: 1.0.0
Hash: 6abedd7919c4457604c0aa44529a6683
Package: R6
Source: CRAN
Version: 2.3.0
Hash: 8eccabbf292b5aba632985cde6406fc3
Package: RColorBrewer
Source: CRAN
Version: 1.1-2
Hash: c0d56cd15034f395874c870141870c25
Package: Rcpp
Source: CRAN
Version: 1.0.0
Hash: c7273c0f0bc9f5e41f4c52a8cf571f0f
Package: assertthat
Source: CRAN
Version: 0.2.0
Hash: e8805df54c65ac96d50235c44a82615c
Package: backports
Source: CRAN
Version: 1.1.3
Hash: a0b8191e6bd2fe71aadd4678bb8f3c98
Package: base64enc
Source: CRAN
Version: 0.1-3
Hash: c590d29e555926af053055e23ee79efb
Package: bindr
Source: CRAN
Version: 0.1.1
Hash: 76578c5f543a6ecbc1365d6445f9ebf7
Package: bindrcpp
Source: CRAN
Version: 0.2.2
Hash: 8ce499301f0dc5c7ff69f0b42e33f5c1
Requires: Rcpp, bindr, plogr
Package: broom
Source: CRAN
Version: 0.5.1
Hash: f170bc989c523e039487511e87c1854f
Requires: backports, dplyr, generics, purrr, reshape2, stringr, tibble,
tidyr
Package: callr
Source: CRAN
Version: 3.1.1
Hash: 461cdebafe2c1cfc23ddc37527633185
Requires: R6, processx
Package: cellranger
Source: CRAN
Version: 1.1.0
Hash: be9d203e7849f73818b36f93e9273c2c
Requires: rematch, tibble
Package: cli
Source: CRAN
Version: 1.0.1
Hash: a742a3229dbf7085c3a737af10e5065b
Requires: assertthat, crayon
Package: clipr
Source: CRAN
Version: 0.4.1
Hash: caf20ae357bfa2ed50e0e7db267f69ce
Package: colorspace
Source: CRAN
Version: 1.3-2
Hash: 0bf8618b585fa98eb23414cd3ab95118
Package: crayon
Source: CRAN
Version: 1.3.4
Hash: ff2840dd9b0d563fc80377a5a45510cd
Package: curl
Source: CRAN
Version: 3.2
Hash: 82a7cf5bb702ef52329b6d23ea6132a7
Package: dbplyr
Source: CRAN
Version: 1.2.2
Hash: f09ea2f1a5c31d86b061d7121fab5db8
Requires: DBI, R6, assertthat, dplyr, glue, purrr, rlang, tibble,
tidyselect
Package: digest
Source: CRAN
Version: 0.6.18
Hash: 65f62365ec69ddd17230d2ffe891a6ab
Package: dplyr
Source: CRAN
Version: 0.7.8
Hash: d6e576944199cba782a471015a822848
Requires: BH, R6, Rcpp, assertthat, bindrcpp, glue, magrittr,
pkgconfig, plogr, rlang, tibble, tidyselect
Package: evaluate
Source: CRAN
Version: 0.12
Hash: c32505adba4f6eca5aa20dd32300b019
Package: fansi
Source: CRAN
Version: 0.4.0
Hash: f147621f72b561485bfffcae78c4f5d5
Package: forcats
Source: CRAN
Version: 0.3.0
Hash: 770f3834b97a2c429bdecb7a5f27eb25
Requires: magrittr, rlang, tibble
Package: fs
Source: CRAN
Version: 1.2.6
Hash: 8ffb8b293a18e26e435465307cc47f75
Requires: Rcpp
Package: generics
Source: CRAN
Version: 0.0.2
Hash: 4aaf002dd434e8c854611c5d11a1d58e
Package: ggplot2
Source: CRAN
Version: 3.1.0
Hash: ef541b05dda10b209d509b5bbaf46ea3
Requires: digest, gtable, lazyeval, plyr, reshape2, rlang, scales,
tibble, viridisLite, withr
Package: glue
Source: CRAN
Version: 1.3.0
Hash: 1fbde6dec830370be696eee8ef31c9e4
Package: gtable
Source: CRAN
Version: 0.2.0
Hash: cd78381a9d3fea966ac39bd0daaf5554
Package: haven
Source: CRAN
Version: 2.0.0
Hash: 3180a95083d9ef6da3fafc38e0519e2f
Requires: Rcpp, forcats, hms, readr, tibble
Package: highr
Source: CRAN
Version: 0.7
Hash: 20757f5c393ed0ecf96c9e8e6d8d514c
Package: hms
Source: CRAN
Version: 0.4.2
Hash: b4096a4f6a6736138e9a825c2baaacf0
Requires: pkgconfig, rlang
Package: htmltools
Source: CRAN
Version: 0.3.6
Hash: 9707abea0a9b7406e98fb1242e97e1f6
Requires: Rcpp, digest
Package: httr
Source: CRAN
Version: 1.4.0
Hash: 62d62d3ffcc9a34411b6e35a813f72dd
Requires: R6, curl, jsonlite, mime, openssl
Package: jsonlite
Source: CRAN
Version: 1.6
Hash: 5f969e213e966135393e3e304abf3f49
Package: knitr
Source: CRAN
Version: 1.21
Hash: 05d92a30fe7f149fef5e82428cbbe0d7
Requires: evaluate, highr, markdown, stringr, xfun, yaml
Package: labeling
Source: CRAN
Version: 0.3
Hash: ecf589b42cd284b03a4beb9665482d3e
Package: lazyeval
Source: CRAN
Version: 0.2.1
Hash: 88926ad9c43581fd0822a37c8ed09f05
Package: lubridate
Source: CRAN
Version: 1.7.4
Hash: a7c783782f0e50be33b31f859c11333e
Requires: Rcpp, stringr
Package: magrittr
Source: CRAN
Version: 1.5
Hash: bdc4d48c3135e8f3b399536ddf160df4
Package: markdown
Source: CRAN
Version: 0.9
Hash: 730f688930cef3223d59bd8aef679ab9
Requires: mime
Package: mime
Source: CRAN
Version: 0.6
Hash: 2ed8f98b8284ad733f3907fc6e2f1334
Package: modelr
Source: CRAN
Version: 0.1.2
Hash: f691854a99ac7814f3853d499408d9a3
Requires: broom, dplyr, magrittr, purrr, rlang, tibble, tidyr
Package: munsell
Source: CRAN
Version: 0.5.0
Hash: 38d0efee9bb99bef143bde41c4ce715c
Requires: colorspace
Package: openssl
Source: CRAN
Version: 1.1
Hash: 82c893294829c4badc3d4133b66d1428
Package: packrat
Source: CRAN
Version: 0.5.0
Hash: 498643e765d1442ba7b1160a1df3abf9
Package: pillar
Source: CRAN
Version: 1.3.1
Hash: 9ed4c2a5d3047bfba3e852ad5e806d91
Requires: cli, crayon, fansi, rlang, utf8
Package: pkgconfig
Source: CRAN
Version: 2.0.2
Hash: b0fd6ed908e150b77e5f00c6478bd58c
Package: plogr
Source: CRAN
Version: 0.2.0
Hash: 81a8008a5e7858552503935f1abe48aa
Package: plyr
Source: CRAN
Version: 1.8.4
Hash: ec185c885aab7ec91693d78c20cb5d1a
Requires: Rcpp
Package: prettyunits
Source: CRAN
Version: 1.0.2
Hash: 49286102a855640daaa38eafe8b1ec30
Requires: assertthat, magrittr
Package: processx
Source: CRAN
Version: 3.2.1
Hash: fdc6a66626b75f96ee28ffc770d9ebd7
Requires: R6, ps
Package: progress
Source: CRAN
Version: 1.2.0
Hash: 0ff5f631b66daf57857f28062f3e6f30
Requires: R6, crayon, hms, prettyunits
Package: ps
Source: CRAN
Version: 1.3.0
Hash: 1d4cae95887ffe5b1a22bea5994476cd
Package: purrr
Source: CRAN
Version: 0.2.5
Hash: 8b0c16db10c7e20b70cd37779a673a8b
Requires: magrittr, rlang, tibble
Package: readr
Source: CRAN
Version: 1.3.1
Hash: ed1b5520a0df4007bc971658ee543b00
Requires: BH, R6, Rcpp, clipr, crayon, hms, tibble
Package: readxl
Source: CRAN
Version: 1.2.0
Hash: 3d49de1375021e909463ce4bdb613327
Requires: Rcpp, cellranger, progress, tibble
Package: rematch
Source: CRAN
Version: 1.0.1
Hash: ad4faf59e7611117ff165817074c50c7
Package: reprex
Source: CRAN
Version: 0.2.1
Hash: b30c7fbcb528a71d7ffcd07c9982589d
Requires: callr, clipr, fs, rlang, rmarkdown, whisker, withr
Package: reshape2
Source: CRAN
Version: 1.4.3
Hash: c950c8ac85b81209635acb3ce21b4cce
Requires: Rcpp, plyr, stringr
Package: rlang
Source: CRAN
Version: 0.3.0.1
Hash: 35fb7a51d5d756c56f793ed9c381fb84
Package: rmarkdown
Source: CRAN
Version: 1.11
Hash: a30b0c41b60d981f41dc8c98f2136297
Requires: base64enc, evaluate, htmltools, jsonlite, knitr, mime,
stringr, tinytex, yaml
Package: rstudioapi
Source: CRAN
Version: 0.8
Hash: 9ba7fe76dcaf96966c449527ca04bb78
Package: rvest
Source: CRAN
Version: 0.3.2
Hash: c69f7526520bad66fd2111ebe8b1364b
Requires: httr, magrittr, selectr, xml2
Package: scales
Source: CRAN
Version: 1.0.0
Hash: 7d9b717abcec656ae7c5c982d72b75e5
Requires: R6, RColorBrewer, Rcpp, labeling, munsell, viridisLite
Package: selectr
Source: CRAN
Version: 0.4-1
Hash: b12802c11e35dec9d16a74d30ed0f3ed
Requires: R6, stringr
Package: stringi
Source: CRAN
Version: 1.2.4
Hash: 03ab60ef7fa4627b38ad67c95ce6b04c
Package: stringr
Source: CRAN
Version: 1.3.1
Hash: 9f417a1d899ed1f080942ab36998e8b5
Requires: glue, magrittr, stringi
Package: tibble
Source: CRAN
Version: 1.4.2
Hash: 83895360ce4f8d2ce92eee00526b5b0b
Requires: cli, crayon, pillar, rlang
Package: tidyr
Source: CRAN
Version: 0.8.2
Hash: 9ff92b9b3c11dfcd94d179b75b85c668
Requires: Rcpp, dplyr, glue, magrittr, purrr, rlang, stringi, tibble,
tidyselect
Package: tidyselect
Source: CRAN
Version: 0.2.5
Hash: fad1cf10c5c4996fca6ca68e0716d2e6
Requires: Rcpp, glue, purrr, rlang
Package: tidyverse
Source: CRAN
Version: 1.2.1
Hash: 1b090209cb20b6fc6eba75de8b7f0b53
Requires: broom, cli, crayon, dbplyr, dplyr, forcats, ggplot2, haven,
hms, httr, jsonlite, lubridate, magrittr, modelr, purrr, readr,
readxl, reprex, rlang, rstudioapi, rvest, stringr, tibble, tidyr,
xml2
Package: tinytex
Source: CRAN
Version: 0.9
Hash: a4ffe98c58eace5a95644d8fd6ca5a50
Requires: xfun
Package: utf8
Source: CRAN
Version: 1.1.4
Hash: f3f97ce59092abc8ed3fd098a59e236c
Package: viridisLite
Source: CRAN
Version: 0.3.0
Hash: 78bb072c4f9e729a283d4c40ec93f9c6
Package: whisker
Source: CRAN
Version: 0.3-2
Hash: 803d662762e532705c2c066a82d066e7
Package: withr
Source: CRAN
Version: 2.1.2
Hash: d534108bcd5f34ec73e9eb523751ba20
Package: xfun
Source: CRAN
Version: 0.4
Hash: 76004125b45195c0330ec71904849995
Package: xml2
Source: CRAN
Version: 1.2.0
Hash: 3f00e5347a6d7ccad2237fe1bc1df6d0
Requires: Rcpp
Package: yaml
Source: CRAN
Version: 2.2.0
Hash: a5ad5616d83d89f8d84cbf3cf4034e13

19
packrat/packrat.opts Normal file
View File

@ -0,0 +1,19 @@
auto.snapshot: TRUE
use.cache: TRUE
print.banner.on.startup: auto
vcs.ignore.lib: TRUE
vcs.ignore.src: TRUE
external.packages:
local.repos:
load.external.packages.on.startup: TRUE
ignored.packages:
ignored.directories:
data
inst
quiet.package.installation: TRUE
snapshot.recommended.packages: FALSE
snapshot.fields:
Imports
Depends
LinkingTo
symlink.system.packages: TRUE

40
vhk.Rmd
View File

@ -99,57 +99,49 @@ raw_data %>% mutate(Duration = RemovalDate - Date) %>%
### Variante A: Absolute Zahlen
```{r removal_reasons, message=FALSE}
raw_data %>% filter(!is.na(RemovalDate), !is.na(RemovalReason)) %>%
mutate(ExplYear = ExplYear %% 100) %>%
group_by(ExplYear) %>%
mutate(ImplYear = ImplYear %% 100) %>%
group_by(ImplYear) %>%
count(RemovalReason) %>%
ggplot(aes(x = ExplYear, y = n)) +
ggplot(aes(x = ImplYear, y = n)) +
geom_point() + geom_line() +
scale_x_continuous(breaks = scales::pretty_breaks()) +
scale_y_continuous(breaks = scales::pretty_breaks()) +
facet_wrap(vars(RemovalReason)) +
labs(x = NULL, y = "Anzahl entfernter Katheter")
labs(x = "Implantationsjahr", y = "Anzahl entfernter Katheter")
```
### Variante B: auf die Zahl der in dem Jahr gelegten Katheter bezogen
```{r removal_reasons_normalized, message=FALSE}
# Zur Berechnung dieses Index muß man zunächst für jeden explantierten Katheter
# berechnen, wie viele Katheter im *ex*plantationsjahr *im*plantiert wurden.
impl_per_year = raw_data %>% mutate(ImplYear = year(Date)) %>% count(ImplYear)
raw_data %>%
select(ImplYear, ExplYear, RemovalDate, RemovalReason) %>%
select(ImplYear, RemovalDate, RemovalReason) %>%
mutate(ImplYear = ImplYear %% 100) %>%
left_join(impl_per_year, by = c("ExplYear" = "ImplYear")) %>% # creates column "n"
filter(!is.na(RemovalDate), !is.na(RemovalReason)) %>%
group_by(ExplYear) %>%
add_count(RemovalReason) %>% # creates column "nn"
ungroup() %>%
select(ExplYear, RemovalReason, n, nn) %>%
group_by(ImplYear) %>%
add_count(ImplYear) %>%
add_count(RemovalReason) %>%
mutate(i = nn/n) %>%
group_by(ExplYear, RemovalReason) %>%
# summarize(i = sum(i)) %>%
distinct() %>%
ggplot(aes(x = ExplYear, y = i)) +
filter(!is.na(RemovalDate), !is.na(RemovalReason)) %>%
ggplot(aes(x = ImplYear, y = i)) +
geom_point() + geom_line() +
scale_x_continuous(breaks = scales::pretty_breaks()) +
scale_y_continuous(breaks = scales::pretty_breaks()) +
facet_wrap(vars(RemovalReason)) +
labs(x = NULL, y = "Anzahl entfernter Katheter / gelegter Katheter")
labs(x = "Implantationsjahr", y = "Anzahl entfernter Katheter / gelegter Katheter")
```
## Wann treten Infektionen auf?
```{r infections, message=FALSE}
raw_data %>% filter(!is.na(RemovalDate), RemovalReason == "Infektion") %>%
mutate(Duration = RemovalDate - Date, Month = as.integer(Duration) %/% 30) %>%
ggplot(aes(x = Month)) +
mutate(Duration = RemovalDate - Date, Week = as.integer(Duration) %/% 7 + 1) %>%
filter(Week <= 56) %>%
ggplot(aes(x = Week)) +
geom_bar(width = 0.9) +
# raw_data %>% filter(!is.na(RemovalDate), RemovalReason == "Infektion") %>%
coord_cartesian(xlim = c(0, 56)) +
scale_x_continuous(breaks = seq(from = 0, to = 56, by = 4)) +
scale_y_continuous(breaks = seq(from = 0, to = 10, by = 1)) +
facet_grid(rows = vars(ImplYear)) +
labs(x = "Woche nach Implantation", y = "Anzahl wg. Infektion entfernter Katheter",
title = "Liegedauer infizierter Katheter nach Implantationsjahr")
title = "Liegedauer infizierter Katheter nach Implantationsjahr",
subtitle = "Die Graphik berücksichtigt nur Infektionen im ersten Jahr")
```