diff --git a/DESCRIPTION b/DESCRIPTION index 5637dd8..bc9a3c4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: nottshcMethods Title: Helper functions for working with NHS healthcare data by the Data Science Team of the Nottinghamshire Healthcare NHS Foundation Trust -Version: 0.1.0 -Date: 2021-03-29 +Version: 0.2.0 +Date: 2021-07-07 Authors@R: c( person("Milan", "Wiedemann", email = "milan.wiedemann@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-1991-282X")), person("Zoe", "Turner", role = c("aut"), comment = c(ORCID = "0000-0003-1033-9158")), @@ -17,3 +17,10 @@ RoxygenNote: 7.1.1 Suggests: testthat (>= 3.0.0) Config/testthat/edition: 3 +Imports: + dplyr, + tidyr, + plotly, + scales, + ggplot2, + lubridate diff --git a/docs/404.html b/docs/404.html index 5d071b6..14c5f16 100644 --- a/docs/404.html +++ b/docs/404.html @@ -71,7 +71,7 @@
diff --git a/docs/CODE_OF_CONDUCT.html b/docs/CODE_OF_CONDUCT.html index c4e11b2..a17546a 100644 --- a/docs/CODE_OF_CONDUCT.html +++ b/docs/CODE_OF_CONDUCT.html @@ -71,7 +71,7 @@ diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 19b8dc4..08e3152 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -71,7 +71,7 @@ diff --git a/docs/LICENSE.html b/docs/LICENSE.html index 029c35d..e1c21f0 100644 --- a/docs/LICENSE.html +++ b/docs/LICENSE.html @@ -71,7 +71,7 @@ diff --git a/docs/authors.html b/docs/authors.html index 1e2041d..9f90613 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -71,7 +71,7 @@ diff --git a/docs/index.html b/docs/index.html index ad37c0c..a426f40 100644 --- a/docs/index.html +++ b/docs/index.html @@ -31,7 +31,7 @@ @@ -71,7 +71,13 @@You can install the the development version from GitHub with:
# install.packages("devtools")
-devtools::install_github("CDU-data-science-team/nottshcMethods")
Once the package is installed, xaringan presentation slides with Nottinghamshire Healthcare NHS Foundation Trust branding can be access easily using the RStudio IDE, by selecting File
-> R markdown ...
-> From Template
.
as_age_groups.Rd
Categorise continuous age into age groups
+as_age_groups( + var, + min = 0, + max = 100, + by = 10, + grouping_method = c("user_defined", "ons_1", "ons_2", "nhs_survey") +)+ +
var | +Name of variable or vector |
+
---|---|
min | +Numeric, specifying the minimum age of the first age group. +Age values lower than this will be returned as missing values (NA) |
+
max | +Numeric, specifying the upper end of the last age group |
+
by | +Numeric, increment of the age categories |
+
method | +String, specyfing the method to be used for grouping age into categories. +Details about the different methods are available here: +"user_defined", "ons_1", "ons_2", "nhs_survey" ... TODO |
+
+# Example using a vector: +set.seed(123) +age <- sample(1:100, 100, replace = T) +as_age_groups(age) +#> [1] 30-39 70-79 50-59 10-19 60-69 40-49 50-59 40-49 10-19 20-29 90-99 90-99 +#> [13] 60-69 90-99 50-59 90-99 0-9 90-99 90-99 70-79 20-29 0-9 40-49 0-9 +#> [25] 80-89 30-39 70-79 80-89 40-49 70-79 10-19 30-39 0-9 0-9 40-49 70-79 +#> [37] 20-29 20-29 60-69 50-59 0-9 50-59 20-29 90-99 30-39 80-89 30-39 90-99 +#> [49] 60-69 70-79 70-79 60-69 10-19 80-89 90-99 90-99 20-29 30-39 20-29 70-79 +#> [61] 40-49 40-49 90-99 60-69 90-99 10-19 90-99 0-9 70-79 80-89 80-89 30-39 +#> [73] 30-39 80-89 50-59 30-39 0-9 10-19 60-69 20-29 50-59 20-29 80-89 30-39 +#> [85] 20-29 80-89 30-39 40-49 30-39 10-19 30-39 30-39 60-69 90-99 10-19 90-99 +#> [97] 90-99 70-79 60-69 20-29 +#> Levels: 0-9 10-19 20-29 30-39 40-49 50-59 60-69 70-79 80-89 90-99 100++# Example using a data frame +tibble::tibble(age = sample(1:115, 100, replace = T)) %>% + dplyr::mutate(age_groups = as_age_groups(age, min = 10, max = 100)) +#> Error in tibble::tibble(age = sample(1:115, 100, replace = T)) %>% dplyr::mutate(age_groups = as_age_groups(age, min = 10, max = 100)): could not find function "%>%"
calc_monthly_freq.Rd
Calculate frequencies of groups per month
+calc_monthly_freq( + data, + by, + date_var_name, + .drop_latest_month = TRUE, + .calc_year_month_day_vars = TRUE +)+ +
data | +Data |
+
---|---|
by | +Grouping variables used in group_by |
+
date_var_name | +String specifying date variable, needs to be class date |
+
.drop_latest_month | +Logical, specifying whether or not to drop the most recent month |
+
.calc_year_month_day_vars | +Logical, specifying whether to calculate separate year, month, and day variable |
+
ggplotly_nottshc.Rd
There are some problems with x and y axis labels when converting +ggplot2 to plotly, especially when using facets. This fun has a workaround that is not perfect.
+ggplotly_nottshc( + ggplot, + xtitle = NULL, + ytitle = NULL, + aes_txt_tooltip = TRUE, + display_mode_bar = FALSE +)+ +
ggplot | +ggplot2 object |
+
---|---|
xtitle | +String, x lab title |
+
ytitle | +String, y lab title |
+
aes_txt_tooltip | +Logical, specifying whether or not to use tooltip |
+
display_mode_bar | +Logical, specifying whether to show the annoying +mode bar from plotly, FALSE by default! |
+
Categorise continuous age into age groups
Calculate frequencies of groups per month
Convert ggplot object into plotly
One way hash a vector
CDU data science team ggplot2 theme
sample_vector.Rd
A ggplot2 theme with a white panel background, no grid lines, +large axis and legend titles, +and increased text padding for better readability.
+sample_vector(values, weights, length)+ +
values | +Vector- the thing you want to sample from |
+
---|---|
weights | +vector of integers the same length as values- the proportions +with which you want to sample |
+
length | +integer- how long you want the return value to be- e.g. the +number of rows in a dataframe |
+
+sample_vector(values = c(NA, "Male", "Female", "Other"), +weights = c(10, 50, 50, 2), +length = 100) +#> [1] "Other" "Male" "Male" "Male" "Female" "Female" "Female" "Female" +#> [9] "Female" "Female" "Female" "Female" "Female" NA "Male" "Male" +#> [17] "Male" "Male" "Male" "Female" "Male" "Male" "Male" "Male" +#> [25] "Female" "Female" "Female" "Male" "Male" "Male" "Male" "Female" +#> [33] "Male" "Male" "Male" "Female" "Male" "Female" "Male" "Male" +#> [41] "Female" "Female" "Male" "Male" "Male" "Female" "Male" "Female" +#> [49] "Female" "Female" "Female" "Male" "Female" "Female" "Female" "Female" +#> [57] "Male" "Female" "Male" "Female" "Female" "Male" "Female" NA +#> [65] NA "Male" "Male" "Other" "Female" NA "Female" "Male" +#> [73] "Female" "Male" "Female" "Male" NA "Female" "Female" "Male" +#> [81] "Female" "Male" "Male" "Male" "Male" "Female" "Male" "Male" +#> [89] "Female" "Male" "Female" "Male" "Male" "Female" NA "Male" +#> [97] NA "Female" "Female" "Male"+