Skip to content

Solid and dashed line.

3 messages · Enoch Gyamfi Ampadu, Ashim Kapoor

#
Dear list,

Please I need some assistance. I have been asked to produce a 1:1 line
(dashed) and a line of best fit (solid) in a scatter plot. I have tried
geom_abline() but it gives only the solid line. I also tried lty("dashed")
to get the dashed line but it not working. I would be glad if I could get
some assistance on how to do it.

Best regards,

Enoch.
#
Dear Enoch,

Would this suffice for you ?

library(ggplot2)

ggplot(mtcars, aes(x=wt, y=mpg)) +
  geom_point( color="black")+
  geom_smooth(method=lm, se=FALSE,
              color="darkred")

ggplot(mtcars, aes(x=wt, y=mpg)) +
  geom_point( color="black")+
  geom_smooth(method=lm, se=FALSE, linetype="dashed",
              color="darkred")

Note : I got these examples from :
http://www.sthda.com/english/wiki/ggplot2-scatter-plots-quick-start-guide-r-software-and-data-visualization

Best Regards,
Ashim




On Sun, Feb 14, 2021 at 1:50 PM Enoch Gyamfi Ampadu <egampadu at gmail.com>
wrote:

  
  
#
Dear Ashim,

Thank you for the response. I will try it out and let you know how it goes.

Best regards,

Enoch.
On Sun, 14 Feb 2021, 10:35 Ashim Kapoor, <ashimkapoor at gmail.com> wrote: