我使用 ggplot2 实现了这个图,我想将 y 轴更改为百分比,从 0% 到 100%,每 10 次中断一次。我知道我可以使用:
+ scale_y_continuous(label=percent, breaks = seq(0,1,.1))
但我仍然遇到问题,因为在转换为百分比时,R 将 30000 解释为 30000%,所以如果限制为 100%,我的图表中什么也得不到。我该如何管理它?
我有一个这样的数据集:
ID time value
1 1 B with G available
2 1 Generic
3 1 B with G available
4 1 Generic
5 1 B with G available
6 1 Generic
7 1 Generic
8 1 Generic
9 1 B with G available
10 1 B with G available
11 1 Generic
12 1 B with G available
13 1 B with G available
14 1 B with G available
15 1 Generic
16 1 B with G available
17 1 B with G available
18 1 B with G available
19 1 B with G available
20 1 B with G available
1 2 B with G available
2 2 Generic
3 2 B with G available
4 2 Generic
5 2 B with G available
6 2 Generic
7 2 Generic
8 2 Generic
9 2 B with G available
10 2 B with G available
11 2 Generic
12 2 B with G available
13 2 B with G available
14 2 B with G available
15 2 Generic
16 2 B with G available
17 2 switch
18 2 B with G available
19 2 B with G available
20 2 switch
可以使用此代码重现:
PIPPO <- data.frame("ID"=rep(c(1:20),2), "time"=c(rep(1,20),rep(2,20)), "value"=c("B","G","B","G","B",rep("G",3),rep("B",2),"G",rep("B",3),"G",rep("B",6),"G","B","G","B",rep("G",3),rep("B",2),"G",rep("B",3),"G","B","switch",rep("B",2),"switch"))
所以我没有可以管理的 y 轴变量。
这是我的代码和我获得的情节
ggplot(PIPPO,
aes(x = time, stratum = value, alluvium = ID,
fill = value, label = value)) +
scale_fill_brewer(type = "qual" , palette = "Set3") +
geom_flow(stat = "flow", knot.pos = 1/4, aes.flow = "forward",
color = "gray") +
geom_stratum() +
theme(legend.position = "bottom")
有人可以帮我吗?
我使用真实数据得到了什么
scale_y_continuous(label = scales::percent_format(scale = 100 / n_id))
最大值为 84%(而不是 100%)。我怎样才能使 y 轴达到 100% 并每 10% 损坏一次?
这是我得到的
scale_y_continuous(breaks = scales::pretty_breaks(10), label = scales::percent_format(scale = 100 / n_id))
我每 14% 得到一个奇怪的值。