Я думаю, что если ваш alpha
должен зависеть от вашей категориальной переменной, вы можете передать его в aes
и установить значения для альфа, используя scale_alpha_manual
:
ggplot(data = df, aes(y = mean, ymin = lower, ymax = upper, x = x, fill = cat, alpha = 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() +
geom_line() +
scale_y_continuous("Predicted probability", labels = scales::percent) +
xlab("X") +
labs(title = "Title")+
scale_alpha_manual(name = "category", values = c(.1, .2, .3, .4))
Пример данных
structure(list(Row = c(1L, 2L, 3L, 4L, 7L, 8L, 9L, 10L, 13L,
14L, 15L, 16L, 19L, 20L, 21L, 22L, 25L, 26L, 27L, 28L, 31L, 32L,
33L, 34L, 37L, 38L, 39L, 40L, 43L, 44L, 45L, 46L, 49L, 50L, 51L,
52L, 55L, 56L, 57L, 58L, 61L, 62L, 63L, 64L), mean = c(0.02298658,
0.0229903, 0.02299402, 0.02299774, 0.03075102, 0.03075596, 0.03076089,
0.03076583, 0.0410672, 0.04107372, 0.04108024, 0.04108676, 0.05469522,
0.05470377, 0.05471233, 0.05472088, 0.07255268, 0.07256381, 0.07257493,
0.07258606, 0.09569158, 0.09570589, 0.09572019, 0.0957345, 0.12522569,
0.12524379, 0.12526188, 0.12527998, 0.16218708, 0.1622095, 0.16223192,
0.16225435, 0.20730452, 0.20733159, 0.20735866, 0.20738574, 0.26073142,
0.2607631, 0.26079479, 0.26082648, 0.32180096, 0.32183675, 0.32187253,
0.32190832), lower = c(0.02001936, 0.0200234, 0.02002744, 0.02003149,
0.02637643, 0.02638214, 0.02638786, 0.02639357, 0.03428711, 0.03429811,
0.03430911, 0.03432012, 0.0434779, 0.04348976, 0.04350163, 0.0435135,
0.05491805, 0.05492779, 0.05493754, 0.0549473, 0.06842579, 0.06844165,
0.06845752, 0.06847338, 0.0854178, 0.08543727, 0.08545674, 0.08547622,
0.10708009, 0.10711512, 0.10715016, 0.1071852, 0.13200609, 0.13202424,
0.1320424, 0.13206056, 0.16270517, 0.16274097, 0.16277678, 0.16281259,
0.19905517, 0.19907373, 0.1990923, 0.19911087), upper = c(0.02629616,
0.02629639, 0.02629662, 0.02629685, 0.03546341, 0.03546877, 0.03547412,
0.03547948, 0.04879853, 0.04880438, 0.04881024, 0.0488161, 0.06729005,
0.06729357, 0.06729748, 0.0673064, 0.09335719, 0.09336202, 0.09336686,
0.0933717, 0.12862716, 0.12863947, 0.12864678, 0.12865291, 0.17360485,
0.17361856, 0.17363227, 0.17364598, 0.23140493, 0.23145163, 0.23149834,
0.23152234, 0.30024572, 0.30026912, 0.30029252, 0.30031592, 0.3793895,
0.37942921, 0.37946892, 0.37950864, 0.46744402, 0.46750282, 0.46756161,
0.46762041), x = c(0L, 0L, 0L, 0L, 5L, 5L, 5L, 5L, 10L, 10L,
10L, 10L, 15L, 15L, 15L, 15L, 20L, 20L, 20L, 20L, 25L, 25L, 25L,
25L, 30L, 30L, 30L, 30L, 35L, 35L, 35L, 35L, 40L, 40L, 40L, 40L,
45L, 45L, 45L, 45L, 50L, 50L, 50L, 50L), cat = c("A", "B", "C",
"D", "A", "B", "C", "D", "A", "B", "C", "D", "A", "B", "C", "D",
"A", "B", "C", "D", "A", "B", "C", "D", "A", "B", "C", "D", "A",
"B", "C", "D", "A", "B", "C", "D", "A", "B", "C", "D", "A", "B",
"C", "D")), row.names = c(NA, -44L), class = c("data.table",
"data.frame"), .internal.selfref = <pointer: 0x56276b4f1350>)