Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
change name from ggmissing to naniar
- Loading branch information
Showing
19 changed files
with
155 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#' @name naniar-ggproto | ||
#' @title naniar-ggroto | ||
#' | ||
#' @description These are the stat and geom overrides using ggproto from ggplot2 that make naniar work. | ||
#' | ||
NULL |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# derive_shadows: | ||
# helpers to clear up common representations of missing values | ||
# such as "NA", "N/A", etc. | ||
# and might allow for an easier way for users to describe different | ||
# missing data codes, such as -99, which might indicate missing, but | ||
# some other kind of missing value, perhaps a different mechanism of | ||
# missingness | ||
# ideas for function names: | ||
# narify (play on clarify) | ||
# darken () | ||
# shade | ||
# refract | ||
|
||
# Other commands that might be useful? | ||
# `is_na` | ||
# `fill_na` | ||
# `drop_na` | ||
# `is_null` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
|
||
# give NAs a more meaningful label | ||
is_na <- function(x) { | ||
factor(is.na(x), levels = c(FALSE, TRUE), labels = c("!NA", "NA")) | ||
} | ||
|
||
# append some shadow cols | ||
|
||
# return a tibble that is a shadow matrix form. | ||
|
||
as_shadow <- function(data){ | ||
|
||
data_shadow <- purrr::map_df(data, is_na) | ||
|
||
names(data_shadow) <- paste0(names(data),"_NA") | ||
|
||
data_shadow | ||
|
||
} | ||
|
||
# as_shadow(airquality) | ||
|
||
bind_shadow <- function(data){ | ||
|
||
# data_shadow <- map_df(data, is_na) | ||
# names(data_shadow) <- paste0(names(data),"_NA") | ||
data_shadow <- as_shadow(data) | ||
|
||
bound_shadow <- tibble::as_tibble(dplyr::bind_cols(data, data_shadow)) | ||
|
||
bound_shadow | ||
|
||
} | ||
|
||
ggplot(data = bind_shadow(airquality), | ||
aes(x = Ozone)) + | ||
geom_histogram() + | ||
facet_wrap(~Solar.R_NA, | ||
ncol = 1) | ||
# | ||
ggplot(data = airquality, | ||
aes(x = Ozone)) + | ||
geom_histogram() + | ||
facet_wrap(~is_na(Solar.R), | ||
ncol = 1) | ||
# | ||
# ggplot(bind_shadow(airquality), | ||
# aes(x = Ozone, | ||
# colour = Solar.R_NA)) + | ||
# geom_density() + | ||
# geom_rug() | ||
# | ||
# ggplot(airquality, | ||
# aes(x = Ozone, | ||
# colour = is_na(Solar.R))) + | ||
# geom_density() + | ||
# geom_rug() | ||
|
||
# other "long" shadow format | ||
|
||
# shadow_join exists as we want to include this extra metadata about the rows that have missing data, but I also wanted to include some extra information about the class of the data, in case we need to gather the data back into a wider, rather than long, format. Here it takes a function `visdat`, `visdat:::fingerprint`, which is currently not a particularly complex function. | ||
|
||
gather_shadow <- function(df){ | ||
|
||
df_val_type <- df %>% | ||
as_data_frame() %>% | ||
purrr::dmap(visdat:::fingerprint) %>% | ||
mutate(rows = row_number()) %>% | ||
tidyr::gather_(key_col = "variable", | ||
value_col = "valueType", | ||
gather_cols = names(.)[-length(.)]) | ||
|
||
# df_shadow | ||
df_shadow <- df %>% | ||
as_data_frame() %>% | ||
mutate(rows = row_number()) %>% | ||
gather(key = variable, | ||
value = value, | ||
-rows) %>% | ||
mutate(shadow_matrix = is_na(value)) %>% | ||
left_join(df_val_type) | ||
|
||
# perhaps define some attributes | ||
|
||
} | ||
|
||
aq_shadow <- gather_shadow(airquality) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
context("missingness_tidiers") | ||
|
||
test_that("percent_missing_* produces a single, numeric number", { | ||
expect_length(ggmissing::percent_missing_df(airquality), 1) | ||
testthat::expect_type(ggmissing::percent_missing_df(airquality), "double") | ||
expect_length(ggmissing::percent_missing_var(airquality), 1) | ||
testthat::expect_type(ggmissing::percent_missing_var(airquality), "double") | ||
expect_length(ggmissing::percent_missing_case(airquality), 1) | ||
testthat::expect_type(ggmissing::percent_missing_case(airquality), "double") | ||
|
||
expect_length(percent_missing_df(airquality), 1) | ||
testthat::expect_type(percent_missing_df(airquality), "double") | ||
|
||
expect_length(percent_missing_var(airquality), 1) | ||
testthat::expect_type(percent_missing_var(airquality), "double") | ||
|
||
expect_length(percent_missing_case(airquality), 1) | ||
testthat::expect_type(percent_missing_case(airquality), "double") | ||
}) | ||
|
||
test_that("table_missing_* produces a data_frame", { | ||
testthat::expect_is(ggmissing::table_missing_var(airquality), "tbl_df") | ||
testthat::expect_is(ggmissing::table_missing_case(airquality), "tbl_df") | ||
testthat::expect_is(table_missing_var(airquality), "tbl_df") | ||
testthat::expect_is(table_missing_case(airquality), "tbl_df") | ||
}) | ||
|
||
|