I have this data frame df
:
POFD POD
1 0.00000000 0.1666667
2 0.01449275 0.1666667
3 0.02898551 0.1666667
4 0.02898551 0.3333333
5 0.04347826 0.3333333
6 0.05797101 0.3333333
7 0.07246377 0.3333333
8 0.08695652 0.3333333
9 0.08695652 0.5000000
10 0.10144928 0.5000000
11 0.10144928 0.6666667
12 0.10144928 0.8333333
13 0.11594203 0.8333333
14 0.13043478 0.8333333
15 0.14492754 0.8333333
16 0.15942029 0.8333333
17 0.31884058 0.8333333
18 0.33333333 0.8333333
19 0.34782609 0.8333333
20 0.34782609 1.0000000
21 0.40579710 1.0000000
22 0.42028986 1.0000000
23 0.43478261 1.0000000
24 0.44927536 1.0000000
25 0.46376812 1.0000000
I plot POFD ~ POD
. In the plot, points colors correspond to their level in POD
. The first issue is that I want to shade the area under each segment with the same color as points of the segment. I tried to apply the solution proposed in this question. But it does not work. The shaded area of all segments is in gray. The second issue is that I tried to define the colors using my cols
variable, but colors do not change. Here is my code:
df$fCategory <- factor(POD)
n.fCategory <- length(unique(POD))
cols <- brewer.pal(n.fCategory, "Set3")
p.roc <- ggplot(data = df, mapping = aes(x = POFD, y = POD, colour = fCategory)) +
geom_line(color=rgb(0,0,0, alpha=0.5), size = 1) +
geom_point(size=4, alpha=0.5) +
scale_colour_discrete(drop=TRUE,
limits = levels(df$fCategory)) +
geom_ribbon(aes(x = POFD, ymax = POD), ymin=0, alpha=0.3) +
scale_fill_manual(values = cols) +
theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"))