Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201945

different alpha values per group in plot

$
0
0

I have the below data

          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

And I use this code to produce a plot

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")

Now, I would like to set different alpha values for each of the categories A, B, C, and D (say, c(.1, .2, .3, .4)) but using geom_ribbon(alpha = c(.1, .2, .3, .4) only produces an error message.

Can someone point me in the right direction?


Viewing all articles
Browse latest Browse all 201945

Trending Articles