I am compiling a report and for some statistical analyses, I am using the z-scores for certain columns in my dataframe. This required me to use the scale function, but recently, I have been tessting out using datawizard instead, where there is a function called datawizard::standardize to accomplish the exact same task.
However, later on in my report, I was showing some plots of the distribution on my data and had been using pivot_longer to show multiple variables in the same graph. It worked when i had the scale function originally, but now I'm struggling with using datawizard::standardize.
My code for the graph is below. I now get an error in pivot_longer_spec(). A screenshot of the full error is below.
! Can't combine variable1.z <dw_transformer> and variable2.z <dw_transformer>.
✖ Some attributes are incompatible.
df %>%
filter(index.visit == visit) %>%
select(ends_with(".z")) %>%
pivot_longer(cols = everything()) %>%
ggplot(aes(x = name, y = value)) +
geom_quasirandom(size = .1)
The thing is, I tried switching to specifying only one biomarker instead of everything in my code and that works, but it seems impossible for me to get more than that. I'd like to show all the data side-by-side in one graph.
You can solve the problem by wrapping the
standardize()transformation inc(), which essentially changes the class fromdw_transformtonumeric. Here's an example withmtcars. First, you can generate the error this way:Here's the code that solves the error by wrapping the output of
standardize()inc().Created on 2023-09-07 with reprex v2.0.2