简体   繁体   中英

Removing (n=0) from sjplot::plot_xtab

I'm trying to remove zero values from my visual using the plot_xtab function from the sjPlot package. I tried using drop.empty = FALSE , but that didn't seem to help.

I just don't like the way the "n=0 (0%)" looks. Does anyone know if this function still works or if there is an alternative?

You could remove the rows in the data from your plot with zeros. So if you save the plot as an object, you can extract the data. By conditionally removing the rows with zeros, these are gone in the plot. I don't have your data, so I created a reproducible example:

df <- data.frame(x = c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4),
                 y = c(1,0,1,2,3,2,1,0,4,3,1,2,0,2,1, 0))
library(sjPlot)
p <- plot_xtab(df$x, df$y)
p

# remove rows with prc = 0:
p$data <- p$data[p$data$prc != 0, ]
p

Created on 2022-08-01 by the reprex package (v2.0.1)

As you can see, the "n=0 (0%)" are gone

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM