sjPlotplot_xtab stack_view

问题描述 投票:0回答:1

如何避免以下情况下的 %0 打印?

library(sjPlot)
library(palmerpenguins)
View(penguins)
plot_xtab(penguins$island, penguins$species, bar.pos = "stack",
margin = "row",  show.n = FALSE)

r graphics label display sjplot
1个回答
0
投票

我没有找到删除

0%
的论据,但我很确定这是可能的。这是我们如何使用
tidyverse
获得相同图表的解决方案:

library(tidyverse)
library(palmerpenguins)

penguins %>%
  count(island, species) %>%
  group_by(island) %>%
  mutate(percentage = n / sum(n) * 100) %>%
  ggplot(aes(x = island, y = percentage, fill = fct_relevel(species, "Chinstrap", "Gentoo", "Adelie"))) +
  geom_bar(stat = "identity", width = 0.5) +
  geom_text(aes(label = scales::percent(percentage / 100)), position = position_stack(vjust = 0.5), size = 10) +
  labs(title = "Percentage of Species within Each Island",  x = "Island", y = "Percentage", fill = "species") +
  scale_y_continuous(labels = scales::percent_format(scale = 1)) +
  scale_fill_manual(values = c("#1f78b4", "#b2df8a",  "#a6cee3"))+
  theme_bw() +
  theme(text = element_text(size = 26))

© www.soinside.com 2019 - 2024. All rights reserved.