How to normalise the y-axis after the summary function in stat_summary is applied?

In the figure below, I calculate a quantity called "overlap probability" for many realisations of the same process, and then plot the mean_se with ggplot.
However, I would like to rescale these curves with y = y / y[x=1] such that both curves start at y=1.
Is there a way to do this in ggplot directly?

ggplot(dt.op,
       aes(x = episode_index, 
           y = overlap_prob,
           group = factor(concentration),
           colour = factor(concentration),
           fill = factor(concentration))) +
  stat_summary_bin(fun = mean, geom="line", bins = 100)+
  stat_summary_bin(fun.data = mean_se,
                   geom="ribbon", alpha=0.2, show.legend = F,
                   colour = NA, bins = 100)+
  geom_hline(yintercept = 1, linetype = "dotted") +
  scale_x_log10() +
  annotation_logticks(sides = "b") +
  scale_colour_manual(values=c("grey","black"))+
  scale_fill_manual(values=c("grey","black"))+
  labs(x = "Time (episodes)",
       y = "Rescaled overlap prob.",
       colour = "Density",
       fill = "Density")+
  theme(aspect.ratio = 3/4, 
        legend.position = "right")

enter image description here

Here is a part of the data.

dput(rbind(head(dt.op, 10), tail(dt.op, 10)))
structure(list(dataset_name = c("D230722T173027734I1", "D230722T173027734I1", 
"D230722T173027734I1", "D230722T173027734I1", "D230722T173027734I1", 
"D230722T173027734I1", "D230722T173027734I1", "D230722T173027734I1", 
"D230722T173027734I1", "D230722T173027734I1", "D230723T012308769I1", 
"D230723T012308769I1", "D230723T012308769I1", "D230723T012308769I1", 
"D230723T012308769I1", "D230723T012308769I1", "D230723T012308769I1", 
"D230723T012308769I1", "D230723T012308769I1", "D230723T012308769I1"
), episode_index = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 
989991L, 989992L, 989993L, 989994L, 989995L, 989996L, 989997L, 
989998L, 989999L, 990000L), overlap_prob = c(0.04, 0.045, 0.035, 
0.04, 0.06, 0.065, 0.09, 0.05, 0.045, 0.04, 0.05, 0.03, 0.05, 
0.04, 0.03, 0.045, 0.03, 0.035, 0.02, 0.015), concentration = c(0.1, 
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.5, 0.5, 0.5, 0.5, 
0.5, 0.5, 0.5, 0.5, 0.5, 0.5), replicate_index = c(1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L)), row.names = c(NA, -20L), class = c("data.table", "data.frame"
), .internal.selfref = <pointer: 0x14a80b0e0>)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.