Closed chapau3 closed 1 year ago
Hi there!
That is a good question,
I can think of two solutions
You can change the theme(text = element_text(size = 6)
Or you can abbreviate the name - I've hacked together these solutions below. I think I'll try and implement an abbreviation mechanism inside the visdat
package, as this is something that has bothered me for some time now.
Let me know if this works for you?
library(visdat)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
df <- as_tibble(airquality) %>%
rename(really_really_really_really_really_really_realllllly_long_name = Ozone)
vis_miss(df)
vis_miss(df) +
theme(text = element_text(size = 6))
nchar_over <- function(x) nchar(x) > 20
nchar_over(state.name)
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [49] FALSE FALSE
df %>%
rename_with(
.fn = ~abbreviate(.x, 10, method = "both"),
# this didn't work with ncar_over for some reason?
.cols = everything()
) %>%
vis_miss()
Created on 2021-09-22 by the reprex package (v2.0.1)
I've added a new function, abbreviate_vars()
to assist with this:
library(visdat)
long_data <- data.frame(
really_really_long_name = c(NA, NA, 1:8),
very_quite_long_name = c(-1:-8, NA, NA),
this_long_name_is_something_else = c(NA, NA,
seq(from = 0, to = 1, length.out = 8))
)
vis_miss(long_data)
long_data %>% abbreviate_vars() %>% vis_miss()
long_data %>% abbreviate_vars(min_length = 5) %>% vis_miss()
long_data %>% abbreviate_vars(min_length = 15) %>% vis_miss()
Created on 2022-10-21 with reprex v2.0.2
Hello, I want to use vis_miss with very long variables, is there a solution to enlarge the graphic part? To avoid that it is overwritten like bellow..
Thanks for your help