Learn R Programming

⚠️There's a newer version (0.6.0) of this package.Take me there.

visdat

How to install

# install.packages("devtools")

devtools::install_github("njtierney/visdat")

What does visdat do?

Initially inspired by csv-fingerprint, vis_dat helps you visualise a dataframe and "get a look at the data" by displaying the variable classes in a dataframe as a plot with vis_dat, and getting a brief look into missing data patterns using vis_miss.

The name visdat was chosen as I think in the future it could be integrated with testdat. The idea being that first you visualise your data (visdat), then you run tests from testdat to fix them.

There are two main commands in the visdat package:

  • vis_dat() visualises a dataframe showing you what the classes of the columns are, and also displaying the missing data.

  • vis_miss() visualises just the missing data, and allows for missingness to be clustered and columns rearranged. vis_miss() is similar to missing.pattern.plot from the mi package. Unfortunately missing.pattern.plot is no longer in the mi package (as of 14/02/2016).

You can read more about visdat in the vignette, "using visdat"".

There are also experimental which are described in more detail in the vignette "Experimental Features of visdat.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Examples

Using vis_dat()

Let's see what's inside the airquality dataset from base R, which contains information about daily air quality measurements in New York from May to September 1973. More information about the dataset can be found with ?airquality.


library(visdat)

vis_dat(airquality)

The plot above tells us that R reads this dataset as having numeric and integer values, with some missing data in Ozone and Solar.R. The classes are represented on the legend, and missing data represented by grey. The column/variable names are listed on the x axis.

By default, vis_dat sorts the columns according to the type of the data in the vectors. You can turn this off by setting sort_type = FALSE.


vis_dat(airquality, 
        sort_type = FALSE)

With many kinds of data

To demonstrate what visdat looks like when you have different kinds of data, we can look at the dataset typical_data, provided within visdat, and created with the excellent wakefield package.


vis_dat(typical_data)

We can also look into using even wider data, looking at typical_larger_data


vis_dat(typical_larger_data)

Using vis_miss()

We can explore the missing data further using vis_miss().


vis_miss(airquality)

The percentages of missing/complete in vis_miss are accurate to 1 decimal place.

You can cluster the missingness by setting cluster = TRUE.


vis_miss(airquality, 
         cluster = TRUE)

The columns can also just be arranged by columns with most missingness, by setting sort_miss = TRUE.


vis_miss(airquality,
         sort_miss = TRUE)

vis_miss indicates when there is a very small amount of missing data at <0.1% missingness.


test_miss_df <- data.frame(x1 = 1:10000,
                           x2 = rep("A", 10000),
                           x3 = c(rep(1L, 9999), NA))

vis_miss(test_miss_df)

vis_miss will also indicate when there is no missing data at all.


vis_miss(mtcars)

Thank yous

Thank you to Ivan Hanigan who first commented this suggestion after I made a blog post about an initial prototype ggplot_missing, and Jenny Bryan, whose tweet got me thinking about vis_dat, and for her code contributions that removed a lot of errors.

Thank you to Hadley Wickham for suggesting the use of the internals of readr to make vis_guess work.

Thank you to Miles McBain for his suggestions on how to improve vis_guess. This resulted in making it at least 2-3 times faster.

Thanks also to Carson Sievert for writing the code that combined plotly with visdat, and for Noam Ross for suggesting this in the first place.

Copy Link

Version

Install

install.packages('visdat')

Monthly Downloads

13,474

Version

0.0.7.9000

License

MIT + file LICENSE

Last Published

February 2nd, 2023

Functions in visdat (0.0.7.9000)

vis_compare

Visually compare two dataframes and see where they are different.
vis_compare_ly

Interactive vis_compare compare two dataframes to find differences.s
add_vis_dat_pal

Add a specific palette to a visdat plot
compare_print

A utility function for vis_dat
typical_data

A small toy dataset of imaginary people
typical_larger_data

A small toy dataset of imaginary people
label_col_missing_pct

(Internal) Create labels for the columns containing the % missing data
miss_guide_label

Label the legend with the percent of missing data
fingerprint

A utility function for vis_dat
guess_type

Guess the type of each individual cell in a dataframe
vis_dat_ly

Interactive plot of data in plotly
vis_extract_value_

(Internal) Add values of each row as a column
vis_guess_ly

Visualise guess in a data.frame
vis_miss

Visualise a data.frame to display missingness.
vis_miss_ly

Interactive plot of missingness in plotly
visdat

visdat
vis_create_

(Internal) Create a boilerploate for visualisations of the vis_ family
vis_dat

Visualises a data.frame to tell you what it contains.
vis_gather_

(Internal) Gather rows into a format appropriate for grid visualisation
vis_guess

Visualise type guess in a data.frame