Regression abline does not show

Hello everyone!

I am trynig to plot a correlation graf using ggplot2, this plot contains 3 geom_abline: (0,1), (intercepet, slope from regression1) and (intercepet, slope from regression2)

I used this script before and worked well, but now the regression abline just appears when I used limits including de intercept value, but I'd like the graph to be from 0, like this:

image

Can someone help me please?

Here is the code:

dat_ap <- tibble(clone = c("3334", "3334", "3334", "3334", "3334", 
                  "3334", "3334", "3334", "3334", "3334", "3334", "3334", "3334", 
                  "3334", "3334", "3334", "3334", "3334", "3334", "3336", "3336", 
                  "3336", "3336", "3336", "3336", "3336", "3336", "3336", "3336", 
                  "3336", "3336", "3336", "3336", "3336", "3336", "3334", "3334", 
                  "3334", "3334", "3334", "3334", "3334", "3334", "3334", "3334", 
                  "3334", "3334", "3334", "3334", "3334", "3334", "3334", "3334", 
                  "3334", "3334", "3336", "3336", "3336", "3336", "3336", "3336", 
                  "3336", "3336", "3336", "3336", "3336", "3336", "3336", "3336", 
                  "3336", "3336", "3336", "3336", "3336"), 
ap_observado = c(1.87088777834092, 
                 1.87088777834092, 1.87088777834092, 1.87088777834092, 1.87088777834092, 
                 1.87088777834092, 1.87088777834092, 1.87088777834092, 1.87088777834092, 
                 1.87088777834092, 1.87088777834092, 1.87088777834092, 1.87088777834092, 
                 1.87088777834092, 1.87088777834092, 1.87088777834092, 1.87088777834092, 
                 1.87088777834092, 1.87088777834092, 3.93549287158548, 3.93549287158548, 
                 3.93549287158548, 3.93549287158548, 3.93549287158548, 3.93549287158548, 
                 3.93549287158548, 3.93549287158548, 3.93549287158548, 3.93549287158548, 
                 3.93549287158548, 3.93549287158548, 3.93549287158548, 3.93549287158548, 
                 3.93549287158548, 3.93549287158548, 1.70473923969439, 1.70473923969439, 
                 1.70473923969439, 1.70473923969439, 1.70473923969439, 1.70473923969439, 
                 1.70473923969439, 1.70473923969439, 1.70473923969439, 1.70473923969439, 
                 1.70473923969439, 1.70473923969439, 1.70473923969439, 1.70473923969439, 
                 1.70473923969439, 1.70473923969439, 1.70473923969439, 1.70473923969439, 
                 1.70473923969439, 1.70473923969439, 1.70473923969439, 1.70473923969439, 
                 1.70473923969439, 1.70473923969439, 1.70473923969439, 1.70473923969439, 
                 1.70473923969439, 1.70473923969439, 1.70473923969439, 1.70473923969439, 
                 1.70473923969439, 1.70473923969439, 1.70473923969439, 1.70473923969439, 
                 1.70473923969439, 1.70473923969439, 1.70473923969439, 1.70473923969439, 
                 1.70473923969439), 
ap_est_ori = c(1.90126340639215, 1.90126340639215, 
               1.90126340639215, 1.93943629438848, 1.93943629438848, 1.93943629438848, 
               1.93943629438848, 1.89455257305711, 1.89455257305711, 1.89455257305711, 
               1.89455257305711, 1.93943629438848, 1.93943629438848, 1.93943629438848, 
               1.93943629438848, 1.93943629438848, 1.93943629438848, 1.93943629438848, 
               1.93943629438848, 3.82807809491712, 3.82807809491712, 3.82807809491712, 
               3.82807809491712, 3.82807809491712, 3.82807809491712, 3.82807809491712, 
               3.82807809491712, 3.82807809491712, 3.82807809491712, 3.82807809491712, 
               3.82807809491712, 3.76201958880157, 3.76201958880157, 3.76201958880157, 
               3.76201958880157, 1.79630504324139, 1.79630504324139, 1.79630504324139, 
               1.79630504324139, 1.80187056933036, 1.80187056933036, 1.80187056933036, 
               1.80187056933036, 1.79630504324139, 1.79630504324139, 1.79630504324139, 
               1.79630504324139, 1.80187056933036, 1.80187056933036, 1.80187056933036, 
               1.80187056933036, 1.80587504705132, 1.80587504705132, 1.80587504705132, 
               1.80587504705132, 1.79630504324139, 1.79630504324139, 1.79630504324139, 
               1.80187056933036, 1.80187056933036, 1.80187056933036, 1.80187056933036, 
               1.80187056933036, 1.80187056933036, 1.80187056933036, 1.80187056933036, 
               1.80187056933036, 1.80187056933036, 1.80187056933036, 1.80187056933036, 
               1.80187056933036, 1.80187056933036, 1.80187056933036, 1.80187056933036))

ap_F4 <- c(3.055039e+02, 1.492271e-24) 
ap_r4 <- 0.9736638
ap_rq4 <- 4.437326
ap_F6 <- c(4.263299e+02, 2.672239e-25)
ap_r6 <- 0.9998125
ap_rq6 <- 4.09155


cor_ap <- ggplot(data = dat_ap) +
  geom_point(aes(x = ap_est_ori, y = ap_observado, color = clone), size = 6) +
  geom_abline(intercept = 0, slope = 1, color = "black", size = 1.8) +
  geom_abline(intercept = -0.5870776, slope = 1.275254, size = 1.5, linetype = "dashed", color = "#8B8282") +
  geom_abline(intercept = -0.2923514, slope = 1.109096, size = 1.5, linetype = "dashed", color = "#836FFF") +
  scale_x_continuous(expand = c(0,0), limits = c(0,7), labels = comma_format(decimal.mark = ",", accuracy = 1),name = "ap estimado") +
  scale_y_continuous(expand = c(0,0), limits = c(0,7), labels = comma_format(decimal.mark = ",", accuracy = 1),name = "ap observado") +
  scale_color_manual(values = c("#8B8282", "#836FFF")) +
  #ggtitle(label = bquote(H[0]~":"~"["~beta[0]~~~beta[1]~"]"=="["~0~~~1~"]")) +
  annotate(geom = "text", x = 2, y = 6.6, label = bquote(p-valor~(3334)==.(ap_F4[[2]])), size = 12) +
  annotate(geom = "text", x = 2, y = 6, label = bquote(p-valor~(3336)==.(ap_F6[[2]])), size = 12) +
  annotate(geom = "text", x = 1.7, y = 5, label = paste("r (3334) = ",round(ap_r4,8)), size = 12)+
  annotate(geom = "text", x = 1.7, y = 4.3, label = paste("r (3336) = ",round(ap_r6,8)), size = 12)+
  annotate(geom = "text", x = 4, y = 2, label = paste("RQEM(%) (3334) =",round(ap_rq4,1)), size = 12)+
  annotate(geom = "text", x = 4, y = 1, label = paste("RQEM(%) (3336) =",round(ap_rq6,1)), size = 12)+
  theme_classic()+
  theme(legend.position=c(0.9,.25),
        legend.title = element_text(size = 40),
        legend.text = element_text(size = 40),
        panel.grid.minor = element_line(size = 0.5),
        axis.ticks.length = unit(0.3, "cm"),
        axis.ticks = element_line(size = 1),
        axis.line = element_line(size = 1.8),
        plot.title = element_text(size = 40, face = "bold"),
        axis.title = element_text(size = 40, color = "black"),
        axis.text = element_text(size = 40, color = "black")); cor_ap

Hello.
Thanks for providing code and data, but you could take further steps to make it more convenient for other forum users to help you.

  1. format text to appear as code in the forum, this looks much better and stops posts getting cumbersome with length. This is done simply by turning on and off formatting with triple backtick lines like this
```
my code goes here
```
  1. share data as code, rather than a table of data, that forum users can not conveniently copy and paste into R, use tools such as the library datapasta, or the base function dput() to share a portion of data in code form, i.e. that can be copied from forum and pasted to R session.
1 Like

I am new to R.
Thank you for the tips!! =)

The code you provided draws a chart with three ablines( black, grey dash, blue dash)
and the axis begins at 0 .

So what should change ?

For me the only abline that shows is the black one. Do you think the problem could be my R version?
I don't know what happens, but this code does not work anymore =(

For me the only abline that shows is the black one.

In your full script, or in the example shared here that I tested from, or both ?

Generally I advise not saving and restoring workspace, so review your rstudio setting for that. That way you can trust when you open a new session, you wont be interfered with by leftovers on previous or other work.

you can and should restart your session, especially when debugging. use Ctrl Shift F10 on pc, or the Session menu to restart.

1 Like

In both scripts.
When you said that worked I remembered that I recently installed the 4.1.0 version and after that the script does not work anymore. Now a installed the 4.0 version and it worked. I don't know why that happend.
Thank you for the help!!

If you have moved to R 4.1 you may also need to update your copy of RStudio.

1 Like

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.