strengejacke / sjPlot

sjPlot - Data Visualization for Statistics in Social Science
https://strengejacke.github.io/sjPlot
603 stars 91 forks source link

Fix for issue #841 #842

Closed douglaswhitaker closed 1 year ago

douglaswhitaker commented 1 year ago

This is fix for issue #841 which was caused by the apply function simplifying results in a way that didn't work for unlist if all items have responses at all points.

Further illustration of the issue:

set.seed(31)
dat1 <- data.frame(matrix(sample(1:4, size = 100, replace = TRUE), ncol = 10))
sjPlot::plot_stackfrq(dat1)
set.seed(32)
dat2 <- data.frame(matrix(sample(1:4, size = 100, replace = TRUE), ncol = 10))
sjPlot::plot_stackfrq(dat2)
sjPlot::plot_stackfrq(dat2, legend.labels = 1:4)

apply(dat1, MARGIN = 2, FUN = function(x) length(unique(x)))
apply(dat2, MARGIN = 2, FUN = function(x) length(unique(x)))

Note that all items in dat2 have 4 different responses, while not all items in dat1 do.

strengejacke commented 1 year ago

Thanks! You may add yourself as contributor to the DESCRIPTION file, if you like.