Comments (2)
Hi, an inverse option is not available at the moment. My suggestion is to overwrite or update this line, this line, and this line to get what you need.
For example, create 2 new functions:
profile_non_missing <- function(data) {
## Declare variable first to pass R CMD check
feature <- num_missing <- pct_missing <- group <- NULL
## Check if input is data.table
is_data_table <- is.data.table(data)
## Detect input data class
data_class <- class(data)
## Set data to data.table
if (!is_data_table) data <- data.table(data)
## Extract missing value distribution
missing_value <- data.table(
"feature" = names(data),
"num_missing" = sapply(data, function(x) {sum(!is.na(x))})
)
missing_value[, feature := factor(feature, levels = feature[order(-rank(num_missing))])]
missing_value[, pct_missing := num_missing / nrow(data)][]
## Set data class back to original
if (!is_data_table) class(missing_value) <- data_class
missing_value
}
plot_missing2 <- function(data,
group = list("Good" = 0.05, "OK" = 0.4, "Bad" = 0.8, "Remove" = 1),
missing_only = FALSE,
geom_label_args = list(),
title = NULL,
ggtheme = theme_gray(),
theme_config = list("legend.position" = c("bottom"))) {
## Declare variable first to pass R CMD check
num_missing <- pct_missing <- Band <- NULL
## Profile missing values
missing_value <- data.table(profile_non_missing(data))
if (missing_only) missing_value <- missing_value[num_missing > 0]
## Sort group based on value
group <- group[sort.list(unlist(group))]
invisible(lapply(seq_along(group), function(i) {
if (i == 1) {
missing_value[pct_missing <= group[[i]], Band := names(group)[i]]
} else {
missing_value[pct_missing > group[[i-1]] & pct_missing <= group[[i]], Band := names(group)[i]]
}
}))
## Create ggplot object
output <- ggplot(missing_value, aes_string(x = "feature", y = "num_missing", fill = "Band")) +
geom_bar(stat = "identity") +
scale_fill_discrete("Band") +
coord_flip() +
xlab("Features") + ylab("Non-Missing Rows") +
guides(fill = guide_legend(override.aes = aes(label = "")))
geom_label_args_list <- list("mapping" = aes(label = paste0(round(100 * pct_missing, 2), "%")))
output <- output +
do.call("geom_label", c(geom_label_args_list, geom_label_args))
## Plot object
class(output) <- c("single", class(output))
plotDataExplorer(
plot_obj = output,
title = title,
ggtheme = ggtheme,
theme_config = theme_config
)
}
and call the new functions:
library(data.table)
library(ggplot2)
library(DataExplorer)
plot_missing2(airquality, group = list("Remove" = 0.05, "Bad" = 0.4, "OK" = 0.8, "Good" = 1))
from dataexplorer.
Thank you, this worked perfectly and much appreciated
from dataexplorer.
Related Issues (20)
- Other plots disappear when DataExplorer::plot_str() called HOT 1
- Insufficient complete rows! Skipping correlation analysis and principal component analysis. HOT 1
- ShinyApp for DataExplorer HOT 1
- Error: pandoc document conversion failed with error 99 HOT 1
- Character conversion problem HOT 3
- Add geom_jitter to boxplot and scatterplot
- plot_scatterplot is ordering the labels wrongly HOT 1
- plot_boxplot() color by group? HOT 1
- Add languates option to report
- Charts run off the edge of PDF pages HOT 1
- Plotting twice when knitting to word HOT 1
- Different correlation meters between create_report and plot_correlation HOT 1
- plot_qq throws Error in `combine_vars()`: ! Faceting variables must have at least one value HOT 1
- Error in create_report
- All discrete features ignored! Nothing to plot! HOT 2
- Landscape mode
- Release DataExplorer 0.8.3
- Nothing to plot HOT 3
- Add 'by' argument to plot_histogram and plot_density HOT 3
- Reverse 'missingness' plot to 'complete entries' HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dataexplorer.