我需要更改geom_mosaic中的轴断裂。以下是我的例子:
my_tibble <-
tibble(a=rep(c("a1","a2"),each=4),
b=rep(rep(c("b1","b2"),each=2),times=2),
c=rep(c("c1","c2"),times=4),
x=seq_along(b)
)
my_tibble |>
ggplot() +
geom_mosaic(aes(x=product(a,b,c),weight=x,fill=a),
divider=c("vspine","hspine","hspine"))

我只想要外部分组变量的标签,如下所示

这可以通过geom_mosaic中简单的函数调用来实现吗?
发布于 2022-02-15 00:10:11
我找到了一个基于这篇文章的解决方案:order and fill with 2 different variables geom_bar ggplot2 R
my_tibble |>
ggplot() +
geom_mosaic(aes(x=product(a,b,c),weight=x,fill=a),
divider=c("vspine","hspine","hspine")) +
labs(x="c") +
scale_x_productlist(breaks=my_tibble |>
group_by(c) |>
summarise(pos = sum(x)) |>
mutate(pos=cumsum(pos/sum(pos)),
lag = lag(pos)) |>
replace_na(list(lag=0)) |>
rowwise() |>
mutate(posx=sum(pos,lag)/2) |>
pull(posx),
labels=my_tibble |>
pull(c) |>
unique())代码还需要清理。
https://stackoverflow.com/questions/71119140
复制相似问题