Skip to content

Commit

Permalink
cleaned up some internal function doco
Browse files Browse the repository at this point in the history
  • Loading branch information
njtierney committed Jul 4, 2018
1 parent b8e900a commit e43f180
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
20 changes: 5 additions & 15 deletions R/vis-compare.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,50 +23,41 @@
vis_compare <- function(df1,
df2){

# could add a parameter, "sort_match", to help with
# could add a parameter, sort_match, to help with
# sort_match logical TRUE/FALSE.
# TRUE arranges the columns in order of most matches.

# make a TRUE/FALSE matrix of the data.
# Tells us whether it is the same (true) as the other dataset, or not (false)

if (!identical(dim(df1), dim(df2))){
stop("Dimensions of df1 and df2 are not the same. vis_compare requires dataframes of identical dimensions.")
if (!identical(dim(df1), dim(df2))) {
stop("vis_compare requires identical dimensions of df1 and df2")
}

v_identical <- Vectorize(identical)

df_diff <- purrr::map2(df1, df2, v_identical) %>%
dplyr::as_data_frame()

d <-
df_diff %>%
d <- df_diff %>%
as.data.frame() %>%
purrr::map_df(compare_print) %>%
vis_gather_() %>%
dplyr::mutate(value_df1 = vis_extract_value_(df1),
value_df2 = vis_extract_value_(df2))

# d$value_df1 <- tidyr::gather_(df1, "variables", "value", names(df1))$value
# d$value_df2 <- tidyr::gather_(df2, "variables", "value", names(df2))$value

# then we plot it
ggplot2::ggplot(data = d,
ggplot2::aes_string(
x = "variable",
y = "rows")) +
# text assists with plotly mouseover
# text = c("value_df1", "value_df2"))) +
# this "test code has been removed as ggplot2 version 3.0.0
# this test code has been removed as ggplot2 version 3.0.0
# breaks.
# Logged in issue https://github.com/ropensci/visdat/issues/89

ggplot2::geom_raster(ggplot2::aes_string(fill = "valueType")) +
# change the colour, so that missing is grey, present is black
# scale_fill_discrete(name = "",
# labels = c("Different",
# "Missing",
# "Same")) +
ggplot2::theme_minimal() +
ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 45,
vjust = 1,
Expand All @@ -75,7 +66,6 @@ vis_compare <- function(df1,
y = "Observations",
# this prevents it from being used in the boilerplate
fill = "Cell Type") +
# ggplot2::scale_x_discrete(limits = names(df_diff)) +
ggplot2::scale_fill_manual(limits = c("same",
"different"),
breaks = c("same", # red
Expand Down
12 changes: 6 additions & 6 deletions vignettes/using_visdat.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,20 @@ head(iris)
Or you can have a `glimpse` at it through `dplyr::glimpse`

```{r glimpse}
dplyr::glimpse(iris)
library(dplyr)
glimpse(iris)
```

Here we see that we have doubles, and a factor. We get some insight into the data.

But we don't always have data like the canonical iris dataset. let's take a look at some data that might be a bit more typical of "messy" data.
But we don't always have data like the canonical iris dataset. let's take a look at some data that might be a bit more typical of "messy" data using the `typical_data` dataset
from the `visdat` package.

```{r visdat-glimpse}
library(visdat)
dplyr::glimpse(typical_data)
glimpse(typical_data)
```

Expand Down Expand Up @@ -76,8 +78,6 @@ Let's see what's inside the dataset `airquality`, which contains information abo

```{r vis_dat}
library(visdat)
vis_dat(airquality)
```
Expand Down

0 comments on commit e43f180

Please sign in to comment.