title: How to add the loess line, slope and intercept in Calibration plot using R?
body: <p>I would like to add the loess line, slope and intercept values to the calibration graph as in the following examples:</p>
  <p><a href="https://i.stack.imgur.com/fpnWV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fpnWV.png" alt="enter image description here" /></a>
  <a href="https://i.stack.imgur.com/ZKOIM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZKOIM.png" alt="enter image description here" /></a></p>
  <p><strong>Would you please explain to me how to add these informations: slope, intercept, legend in th e bottom 'Ideal, nonparametric ...'?</strong></p>
  <p>My code is as follows:</p>
  <pre><code>Y &lt;- c(0.4733333, 0.5133333, 0.5400000, 0.5066667, 0.4400000, 0.4733333, 0.4733333, 0.4600000, 0.3933333, 0.5000000, 0.5533333, 0.6266667, 0.5600000, 0.5800000, 0.6000000, 0.5133333, 0.5066667, 0.5933333, 0.5533333, 0.5266667, 0.6800000, 0.6400000, 0.6333333, 0.7266667, 0.6200000, 0.6400000, 0.6200000, 0.7266667, 0.5800000, 0.6066667, 0.6400000, 0.6600000, 0.6066667, 0.6400000, 0.6600000, 0.7266667, 0.6266667, 0.6933333, 0.7000000, 0.7266667, 0.6866667, 0.6933333, 0.6733333, 0.7666667, 0.7200000, 0.6733333, 0.7666667, 0.7266667, 0.6733333, 0.6733333, 0.7133333, 0.6800000, 0.6733333, 0.6866667, 0.7466667, 0.7533333, 0.7200000, 0.7066667, 0.7533333, 0.7933333, 0.8000000, 0.7466667, 0.7466667, 0.7133333, 0.8133333,
                 0.7400000, 0.7666667, 0.6866667, 0.7933333, 0.6866667, 0.7533333, 0.7266667, 0.7533333, 0.7866667, 0.8000000, 0.8200000, 0.7600000, 0.7266667, 0.8200000, 0.8333333, 0.8066667, 0.8533333, 0.7600000, 0.8200000, 0.7600000, 0.8333333, 0.8066667, 0.8333333, 0.7733333, 0.8333333, 0.8600000, 0.8133333, 0.8466667, 0.8266667, 0.8533333, 0.8733333, 0.8666667, 0.8400000, 0.8200000, 0.7866667)
  
  X &lt;- c(0.4333150, 0.4333150, 0.4333150, 0.4333150, 0.4333150, 0.4333150, 0.4333150, 0.4333150, 0.4333150, 0.4333150,
                  0.5448904, 0.5448904, 0.5448904, 0.5448904, 0.5448904, 0.5448904, 0.5448904, 0.5448904, 0.5448904, 0.5448904, 
                  0.6054196, 0.6054196, 0.6054196, 0.6054196, 0.6054196, 0.6054196, 0.6054196, 0.6054196, 0.6054196, 0.6054196, 
                  0.6522453, 0.6522453, 0.6522453, 0.6522453, 0.6522453, 0.6522453, 0.6522453, 0.6522453, 0.6522453, 0.6522453, 
                  0.6934611, 0.6934611, 0.6934611, 0.6934611, 0.6934611, 0.6934611, 0.6934611, 0.6934611, 0.6934611, 0.6934611, 
                  0.7327415, 0.7327415, 0.7327415, 0.7327415, 0.7327415, 0.7327415, 0.7327415, 0.7327415, 0.7327415, 0.7327415, 
                  0.7666206, 0.7666206, 0.7666206, 0.7666206, 0.7666206, 0.7666206, 0.7666206, 0.7666206, 0.7666206, 0.7666206, 
                  0.7984136, 0.7984136, 0.7984136, 0.7984136, 0.7984136, 0.7984136, 0.7984136, 0.7984136, 0.7984136, 0.7984136, 
                  0.8300506, 0.8300506, 0.8300506, 0.8300506, 0.8300506, 0.8300506, 0.8300506, 0.8300506, 0.8300506, 0.8300506, 
                  0.8732516, 0.8732516, 0.8732516, 0.8732516, 0.8732516, 0.8732516, 0.8732516, 0.8732516, 0.8732516, 0.8732516)
  attr(X, &quot;names&quot;) = rep(as.character(0:9),each = 10)
  gr &lt;- rep(1:10,each = 10)
  DATA=data.frame(Y,X,gr)
  DATA$x2 = as.numeric(as.character(DATA$X))
  cols = c(&quot;Reference&quot;=&quot;gray70&quot;,&quot;Lowess&quot; = &quot;royalblue3&quot; ,&quot;Grouped&quot;=&quot;darkorange2&quot;)
  
  ggplot(DATA, aes(x2,Y, group = gr))+ 
    xlim(0,1)+
    ylim(0,1)+
    geom_boxplot()+
    geom_smooth(method = &quot;loess&quot;, se=FALSE, aes(group=1, colour =&quot;Lowess&quot;),size=0.8)+
    geom_abline(aes(slope = 1, intercept = 0,colour= &quot;Reference&quot;),linetype=2)+
    theme_light()+  
    theme(legend.position = c(.97, .1),
          legend.justification = c(&quot;right&quot;, &quot;bottom&quot;),
          legend.box.just = &quot;right&quot;,
          legend.margin = margin(6, 6, 6, 6))+
    labs(title=&quot;Calibration plot&quot;,
         x =&quot;Predicted values&quot;,
         y = &quot;Observed values&quot;)+
    stat_summary(aes(group=X, colour = &quot;Grouped&quot;),fun.y=function(x){mean(x, na.rm = T)}, 
                 geom=&quot;point&quot;, shape=23)+
    scale_colour_manual(name=&quot;&quot;,values=cols)+
    scale_shape_manual(values=c(23, 32, 1))
  </code></pre>
  <p>I get the following graph:
  <a href="https://i.stack.imgur.com/25bw5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/25bw5.png" alt="enter image description here" /></a></p>
  <p>with, the red circles representing the averages and I want to add the intercept and the slope (y = a + bx) of these points. As well as the curve that passes through the median of the boxplots. I also have a problem with the shape of the legend that does not match the red diamond, solid line and dotted line.</p>
  <p>Respectfully,</p>