-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request - Rotate vis_miss figure #170
Comments
Hi there, Thanks for your question! I won't be able to support this unfortunately - it will add complexity to the code, and I'll need some option like "rotate = TRUE". Unfortunately due to the way the plots are created, it isn't as simple as adding "coord_flip()", sorry! Ultimately I would prefer to keep all of the visdat plots the same style. While I won't add this feature, I did want to show you how to create a similar plot that would get your most of the way there, although it doesn't have the missingness text summaries, using a recent version of visdat allows you to get the data out that is used in the plots. Hopefully this helps you! library(ggplot2)
library(visdat)
data <- data.frame(
var1 = c(1, NA, 3, 4, 5),
var2 = c(NA, 2, 3, NA, 5),
var3 = c(1, 2, NA, 4, 5)
)
visdat::vis_miss(data) p <- visdat::vis_miss(data)
p p + coord_flip() vis_miss_data <- visdat::data_vis_miss(data)
vis_miss_data
#> # A tibble: 15 × 4
#> rows variable valueType value
#> <int> <chr> <chr> <chr>
#> 1 1 var1 FALSE FALSE
#> 2 1 var2 TRUE TRUE
#> 3 1 var3 FALSE FALSE
#> 4 2 var1 TRUE TRUE
#> 5 2 var2 FALSE FALSE
#> 6 2 var3 FALSE FALSE
#> 7 3 var1 FALSE FALSE
#> 8 3 var2 FALSE FALSE
#> 9 3 var3 TRUE TRUE
#> 10 4 var1 FALSE FALSE
#> 11 4 var2 TRUE TRUE
#> 12 4 var3 FALSE FALSE
#> 13 5 var1 FALSE FALSE
#> 14 5 var2 FALSE FALSE
#> 15 5 var3 FALSE FALSE
# based off of `visdat:::vis_dat_create_`
ggplot(data = vis_miss_data,
aes(
x = variable,
y = rows
)) +
geom_raster(aes(
fill = valueType
)) +
theme_minimal() +
theme(
axis.text.x = element_text(
angle = 45,
vjust = 1,
hjust = 1
)
) +
labs(
x = "",
y = "Observations"
) +
coord_flip() +
# scale_y_reverse() +
theme(
axis.text.x = element_text(hjust = 0.5)
) +
guides(
colour = "none"
) +
scale_fill_manual(name = "",
values = c("grey80", "grey20"),
labels = c("Present",
"Missing")) +
guides(fill = guide_legend(reverse = TRUE)) Created on 2024-12-02 with reprex v2.1.1
|
Sounds good, thank you for the demo! |
Would it be possible to add an option for the vis_miss function to output figures with observations on the x-axis and variables on the y-axis? Simply transposing the ggplot itself does not work, as demonstrated below. It simply switches the labels on the axes, rather than changing the plot itself
The text was updated successfully, but these errors were encountered: