sjPlot icon indicating copy to clipboard operation
sjPlot copied to clipboard

Enabling weights column in sjplot data selection

Open joelem opened this issue 9 months ago • 0 comments

Hi Daniel,

First, thank you for such an amazing R package, it is so useful! I wanted to request the ability to include weights in the sjplot function, which is meant to be pipe friendly.

As an example, right now this is the way we would plot a cross tab with weights included, basically the weight column is fed by referring back to the original DF:

data %>% 
  select(A, B) %>% 
  sjplot(fun = 'xtab',
         weight.by = data$weight)

However, in a piping pipeline, we often want to filter or preprocess before sending the data to sjplot, so having the ability to also select and pipe the weight column would be really helpful (otherwise we would need to have additional/redundant, and thus potentially error prone, code that also filters the original DF for the weight column). The following tries throw out error "Can't extract columns past the end":

data %>% 
  select(A, B, weights) %>% 
  sjplot(fun = 'xtab',
         weight.by = weights)

data %>% 
  select(A, B, weights) %>% 
  sjplot(fun = 'xtab',
         weight.by = .$weights)

But it could be that maybe there is already a way to do this and I am missing it.

Thank you for any help!

joelem avatar May 25 '24 15:05 joelem