'Using geom_raster to visualise a dataframe of datatypes in R

I am putting together a workflow in R that will ultimately be used to assist in migrating a series of very large databases that are similar, but frustratingly different in minor ways.

One of the things I need to be able to visualise is which variable names are present in each database, and what datatype they are.

I have reached the point where I have a summary dataframe that looks very similar to the example below.

category <- c("Location", "Date", "Time", "Number")
species1 <- c("character", "character", "character", "integer")
species2 <- c("integer", "integer", NA, "character")
species3 <- c("character", "posix", "posix", "integer")
species4 <- c(NA, NA, "posix", "integer")

comparison_table <- data.frame(category, species1, species2, species3, species4)

The NA values denote that this variable is not present within a specific database.

My ultimate goal was to construct a plot of coloured squares to easily identify inconsistent datatypes between the databases (for example, where dates have been recorded as integers instead of POSIX, or where latitude recorded as a character instead of an integer).

My gut tells me that the geom_raster in ggplot2 should be the simplest way to achieve this, but I keep coming up short. I know that I need to define the fill in the aesthetic, but every attempt is met with a different error.

comparison_table %>% 
  ggplot(aes(x = colnames(comparison_table), y = rownames(comparison_table))) +
  geom_raster()

A fresh pair of eyes and a less tired brain would be deeply appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source