strengejacke / sjPlot

sjPlot - Data Visualization for Statistics in Social Science

Home Page:https://strengejacke.github.io/sjPlot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

plot_stackfrq gives an error when legend.labels not specified under some conditions

douglaswhitaker opened this issue · comments

If every item has the same number of chosen responses and legend.labels is not specified, an error is generated by the code that tries to guess the legend labels.

Minimal working example:

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

image

Minimal error example:

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

Error:

Error in `levels<-`(`*tmp*`, value = as.character(levels)) : 
  factor level [2] is duplicated

If legend.labels is specified, there is no error:

sjPlot::plot_stackfrq(dat2, legend.labels = 1:4)

image