Missing data values plot in R


Is there any option to plot the missing values in R ? if yes, kindly help me out.

I googled it and found the below code, but couldn’t understand the X2,X1 and Value in this code. Can anyone explain me asap as i do have a presentation.

And let’s explore the missing data using my own ggplot function:

A function that plots missingness

requires reshape2


ggplot_missing <- function(x){

x %>%
is.na %>%
melt %>%
ggplot(data = .,
aes(x = X2,
y = X1)) +
geom_raster(aes(fill = value)) +
scale_fill_grey(name = “”,
labels = c(“Present”,“Missing”)) +
theme_minimal() +
theme(axis.text.x = element_text(angle=45, vjust=0.5)) +
labs(x = “Variables in Dataset”,
y = “Rows / observations”)

Let’s test it out



VIM has a nice plot for missing values.

Mice also gives some information which you can store in a data set and use ggplot for plotting missing values indirectly.


aggr_plot <- aggr(somedataset, col=c(‘Green’,‘red’),
numbers=TRUE, sortVars=TRUE, labels=names(data),
cex.axis=.7, gap=3, ylab=c(“Histogram of missing data”,“Pattern”))