gpt4 book ai didi

r - 图中每组不同的 alpha 值

转载 作者:行者123 更新时间:2023-12-01 11:11:22 25 4
gpt4 key购买 nike

我有以下数据

          mean      lower      upper   x  cat
1 0.02298658 0.02001936 0.02629616 0 A
2 0.02299030 0.02002340 0.02629639 0 B
3 0.02299402 0.02002744 0.02629662 0 C
4 0.02299774 0.02003149 0.02629685 0 D
7 0.03075102 0.02637643 0.03546341 5 A
8 0.03075596 0.02638214 0.03546877 5 B
9 0.03076089 0.02638786 0.03547412 5 C
10 0.03076583 0.02639357 0.03547948 5 D
13 0.04106720 0.03428711 0.04879853 10 A
14 0.04107372 0.03429811 0.04880438 10 B
15 0.04108024 0.03430911 0.04881024 10 C
16 0.04108676 0.03432012 0.04881610 10 D
19 0.05469522 0.04347790 0.06729005 15 A
20 0.05470377 0.04348976 0.06729357 15 B
21 0.05471233 0.04350163 0.06729748 15 C
22 0.05472088 0.04351350 0.06730640 15 D
25 0.07255268 0.05491805 0.09335719 20 A
26 0.07256381 0.05492779 0.09336202 20 B
27 0.07257493 0.05493754 0.09336686 20 C
28 0.07258606 0.05494730 0.09337170 20 D
31 0.09569158 0.06842579 0.12862716 25 A
32 0.09570589 0.06844165 0.12863947 25 B
33 0.09572019 0.06845752 0.12864678 25 C
34 0.09573450 0.06847338 0.12865291 25 D
37 0.12522569 0.08541780 0.17360485 30 A
38 0.12524379 0.08543727 0.17361856 30 B
39 0.12526188 0.08545674 0.17363227 30 C
40 0.12527998 0.08547622 0.17364598 30 D
43 0.16218708 0.10708009 0.23140493 35 A
44 0.16220950 0.10711512 0.23145163 35 B
45 0.16223192 0.10715016 0.23149834 35 C
46 0.16225435 0.10718520 0.23152234 35 D
49 0.20730452 0.13200609 0.30024572 40 A
50 0.20733159 0.13202424 0.30026912 40 B
51 0.20735866 0.13204240 0.30029252 40 C
52 0.20738574 0.13206056 0.30031592 40 D
55 0.26073142 0.16270517 0.37938950 45 A
56 0.26076310 0.16274097 0.37942921 45 B
57 0.26079479 0.16277678 0.37946892 45 C
58 0.26082648 0.16281259 0.37950864 45 D
61 0.32180096 0.19905517 0.46744402 50 A
62 0.32183675 0.19907373 0.46750282 50 B
63 0.32187253 0.19909230 0.46756161 50 C
64 0.32190832 0.19911087 0.46762041 50 D

然后我用这段代码制作了一个图

ggplot(data = data, aes(y = mean, ymin = lower, ymax = upper, x = x, fill = cat)) +
scale_fill_manual("category", values = c("#11CC66","#2277FF", "#AFAFAF", "#BA0000"),
labels = c("A", "B", "C", "D")) +
theme_classic() +
theme(legend.position = "right") +
geom_ribbon(alpha = 0.35) +
geom_line() +
scale_y_continuous("Predicted probability", labels = scales::percent) +
xlab("X") +
labs(title = "Title")

现在,我想为每个类别 ABC 设置不同的 alpha 值> 和 D(例如,c(.1, .2, .3, .4))但使用 geom_ribbon(alpha = c(.1, .2, .3, .4) 仅生成错误消息。

有人能指出我正确的方向吗?

最佳答案

您首先在 cols 上设置 alpha,因为您的线条总是黑色的:

COLS = c("#11CC66","#2277FF", "#AFAFAF", "#BA0000")
avalues= c(.1, .2, .3, .4)
fillCOLS = sapply(1:4,function(i)alpha(COLS[i],avalues[i]))

ggplot(data = data, aes(y = mean, ymin = lower, ymax = upper, x = x, fill = cat)) +
scale_fill_manual("category", values = fillCOLS,
labels = c("A", "B", "C", "D")) +
theme_classic() +
theme(legend.position = "right") +
geom_ribbon() +
geom_line() +
scale_y_continuous("Predicted probability",
labels = scales::percent) +
xlab("X") +
labs(title = "Title") +
facet_wrap(~cat)

enter image description here

没有 alpha 的绘图:

ggplot(data = data, aes(y = mean, ymin = lower, ymax = upper, x = x, fill = cat)) +
scale_fill_manual("category", values = fillCOLS,
labels = c("A", "B", "C", "D")) +
theme_classic() +
theme(legend.position = "right") +
geom_ribbon() +
geom_line() +
scale_y_continuous("Predicted probability",
labels = scales::percent) +
xlab("X") +
labs(title = "Title") +
facet_wrap(~cat)

enter image description here

关于r - 图中每组不同的 alpha 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59990482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com