mirror of
https://github.com/msberends/AMR.git
synced 2025-07-11 15:01:53 +02:00
(v2.1.1.9186) replace antibiotics
with antimicrobials
!
This commit is contained in:
@ -27,111 +27,113 @@
|
||||
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
|
||||
# ==================================================================== #
|
||||
|
||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE) &&
|
||||
AMR:::pkg_is_available("ggplot2", also_load = TRUE)) {
|
||||
pdf(NULL) # prevent Rplots.pdf being created
|
||||
test_that("ggplot_sir works", {
|
||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE) &&
|
||||
AMR:::pkg_is_available("ggplot2", also_load = TRUE)) {
|
||||
pdf(NULL) # prevent Rplots.pdf being created
|
||||
|
||||
# data should be equal
|
||||
expect_equal(
|
||||
(example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
ggplot_sir())$data %>%
|
||||
summarise_all(resistance) %>%
|
||||
as.double(),
|
||||
example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
summarise_all(resistance) %>%
|
||||
as.double()
|
||||
)
|
||||
# data should be equal
|
||||
expect_equal(
|
||||
(example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
ggplot_sir())$data %>%
|
||||
summarise_all(resistance) %>%
|
||||
as.double(),
|
||||
example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
summarise_all(resistance) %>%
|
||||
as.double()
|
||||
)
|
||||
|
||||
expect_inherits(
|
||||
example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
ggplot_sir(x = "interpretation", facet = "antibiotic"),
|
||||
"gg"
|
||||
)
|
||||
expect_inherits(
|
||||
example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
ggplot_sir(x = "antibiotic", facet = "interpretation"),
|
||||
"gg"
|
||||
)
|
||||
expect_inherits(
|
||||
example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
ggplot_sir(x = "interpretation", facet = "antibiotic"),
|
||||
"gg"
|
||||
)
|
||||
expect_inherits(
|
||||
example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
ggplot_sir(x = "antibiotic", facet = "interpretation"),
|
||||
"gg"
|
||||
)
|
||||
|
||||
expect_equal(
|
||||
(example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
ggplot_sir(x = "interpretation", facet = "antibiotic"))$data %>%
|
||||
summarise_all(resistance) %>%
|
||||
as.double(),
|
||||
example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
summarise_all(resistance) %>%
|
||||
as.double()
|
||||
)
|
||||
expect_equal(
|
||||
(example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
ggplot_sir(x = "interpretation", facet = "antibiotic"))$data %>%
|
||||
summarise_all(resistance) %>%
|
||||
as.double(),
|
||||
example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
summarise_all(resistance) %>%
|
||||
as.double()
|
||||
)
|
||||
|
||||
expect_equal(
|
||||
(example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
ggplot_sir(x = "antibiotic", facet = "interpretation"))$data %>%
|
||||
summarise_all(resistance) %>%
|
||||
as.double(),
|
||||
example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
summarise_all(resistance) %>%
|
||||
as.double()
|
||||
)
|
||||
expect_equal(
|
||||
(example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
ggplot_sir(x = "antibiotic", facet = "interpretation"))$data %>%
|
||||
summarise_all(resistance) %>%
|
||||
as.double(),
|
||||
example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
summarise_all(resistance) %>%
|
||||
as.double()
|
||||
)
|
||||
|
||||
expect_equal(
|
||||
(example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
ggplot_sir(x = "antibiotic", facet = "interpretation"))$data %>%
|
||||
summarise_all(count_resistant) %>%
|
||||
as.double(),
|
||||
example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
summarise_all(count_resistant) %>%
|
||||
as.double()
|
||||
)
|
||||
expect_equal(
|
||||
(example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
ggplot_sir(x = "antibiotic", facet = "interpretation"))$data %>%
|
||||
summarise_all(count_resistant) %>%
|
||||
as.double(),
|
||||
example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
summarise_all(count_resistant) %>%
|
||||
as.double()
|
||||
)
|
||||
|
||||
# support for scale_type ab and mo
|
||||
expect_inherits(
|
||||
(data.frame(
|
||||
mo = as.mo(c("e. coli", "s aureus")),
|
||||
n = c(40, 100)
|
||||
) %>%
|
||||
ggplot(aes(x = mo, y = n)) +
|
||||
geom_col())$data,
|
||||
"data.frame"
|
||||
)
|
||||
expect_inherits(
|
||||
(data.frame(
|
||||
ab = as.ab(c("amx", "amc")),
|
||||
n = c(40, 100)
|
||||
) %>%
|
||||
ggplot(aes(x = ab, y = n)) +
|
||||
geom_col())$data,
|
||||
"data.frame"
|
||||
)
|
||||
# support for scale_type ab and mo
|
||||
expect_inherits(
|
||||
(data.frame(
|
||||
mo = as.mo(c("e. coli", "s aureus")),
|
||||
n = c(40, 100)
|
||||
) %>%
|
||||
ggplot(aes(x = mo, y = n)) +
|
||||
geom_col())$data,
|
||||
"data.frame"
|
||||
)
|
||||
expect_inherits(
|
||||
(data.frame(
|
||||
ab = as.ab(c("amx", "amc")),
|
||||
n = c(40, 100)
|
||||
) %>%
|
||||
ggplot(aes(x = ab, y = n)) +
|
||||
geom_col())$data,
|
||||
"data.frame"
|
||||
)
|
||||
|
||||
expect_inherits(
|
||||
(data.frame(
|
||||
ab = as.ab(c("amx", "amc")),
|
||||
n = c(40, 100)
|
||||
) %>%
|
||||
ggplot(aes(x = ab, y = n)) +
|
||||
geom_col())$data,
|
||||
"data.frame"
|
||||
)
|
||||
expect_inherits(
|
||||
(data.frame(
|
||||
ab = as.ab(c("amx", "amc")),
|
||||
n = c(40, 100)
|
||||
) %>%
|
||||
ggplot(aes(x = ab, y = n)) +
|
||||
geom_col())$data,
|
||||
"data.frame"
|
||||
)
|
||||
|
||||
# support for manual colours
|
||||
expect_inherits(
|
||||
suppressWarnings((ggplot(data.frame(
|
||||
x = c("Value1", "Value2", "Value3"),
|
||||
y = c(1, 2, 3),
|
||||
z = c("Value4", "Value5", "Value6")
|
||||
)) +
|
||||
geom_col(aes(x = x, y = y, fill = z)) +
|
||||
scale_sir_colours(aesthetics = "fill", Value4 = "S", Value5 = "I", Value6 = "R"))$data),
|
||||
"data.frame"
|
||||
)
|
||||
}
|
||||
# support for manual colours
|
||||
expect_inherits(
|
||||
suppressWarnings((ggplot(data.frame(
|
||||
x = c("Value1", "Value2", "Value3"),
|
||||
y = c(1, 2, 3),
|
||||
z = c("Value4", "Value5", "Value6")
|
||||
)) +
|
||||
geom_col(aes(x = x, y = y, fill = z)) +
|
||||
scale_sir_colours(aesthetics = "fill", Value4 = "S", Value5 = "I", Value6 = "R"))$data),
|
||||
"data.frame"
|
||||
)
|
||||
}
|
||||
})
|
||||
|
Reference in New Issue
Block a user