How can I avoid the %0 print for the following scenario ?
library(sjPlot)
library(palmerpenguins)
View(penguins)
plot_xtab(penguins$island, penguins$species, bar.pos = "stack",
margin = "row", show.n = FALSE)
How can I avoid the %0 print for the following scenario ?
library(sjPlot)
library(palmerpenguins)
View(penguins)
plot_xtab(penguins$island, penguins$species, bar.pos = "stack",
margin = "row", show.n = FALSE)
stefan
On
Besides creating the plot from scratch using ggplot2 as in the approach by @TarJae you could just add the value labels manually using a geom_text which allows to conditionally use an empty string a the label for zero counts.
library(sjPlot)
#> #refugeeswelcome
library(palmerpenguins)
library(ggplot2)
p <- plot_xtab(
penguins$island, penguins$species,
bar.pos = "stack",
margin = "row", show.n = FALSE,
show.values = FALSE
)
p +
geom_text(
aes(
y = ypos,
label = ifelse(
prc > 0,
sprintf("%.01f%%", 100 * .data$prc),
""
)
)
)


I did not find an argument to remove the
0%but I am quite sure that is possible. Here is a solution how we could get the same graph usingtidyverse: