banner



How To Draw A Vertical Line In R Histogram

abline R function : An easy fashion to add straight lines to a plot using R software

  • Add a vertical line
  • Add an horizontal line
  • Add regression line
  • Infos

The aim of this tutorial is to show yous how to add together 1 or more direct lines to a graph using R statistical software. The R part abline() can exist used to add vertical, horizontal or regression lines to a graph.

How to add straight lines to a plot using R statistical software

A simplified format of the abline() part is :

              abline(a=Goose egg, b=Zip, h=NULL, v=Naught, ...)            

  • a, b : single values specifying the intercept and the gradient of the line
  • h : the y-value(south) for horizontal line(southward)
  • 5 : the ten-value(south) for vertical line(s)

Add together a vertical line

The simplified format is :

                abline(v = y)              

It draws a vertical line on the current plot at the specified 'y' coordinates.

                # commencement example : Add one line plot(cars) abline(five=15, col="blue") # second case : add 2 lines  # change line colors, sizes and types plot(cars) abline(v=c(15,20), col=c("bluish", "red"), lty=c(1,ii), lwd=c(1, iii)) # third example gear up.seed(1234); mydata<-rnorm(200) hist(mydata, col="lightblue") abline(v = mean(mydata), col="red", lwd=iii, lty=2)              

How to add straight lines to a plot using R statistical software How to add straight lines to a plot using R statistical software How to add straight lines to a plot using R statistical software

Annotation that, line types (lty) and line width (lwd) are explained here.

Add an horizontal line

The simplified format is :

                abline(h = x)              

It draws an horizontal line on the current plot at the specified 'x' coordinates.

                plot(cars) abline(h=xl, col="bluish")              

How to add straight lines to a plot using R statistical software

Add regression line

lm() function is used to fit linear models.

                par(mgp=c(2,one,0), mar=c(3,three,1,1)) # Fit regression line require(stats) reg<-lm(dist ~ speed, data = cars) coeff=coefficients(reg) # equation of the line :  eq = paste0("y = ", circular(coeff[2],1), "*x ", round(coeff[1],one)) # plot plot(cars, master=eq) abline(reg, col="blue")              

How to add straight lines to a plot using R statistical software

Infos

This analysis has been performed using R statistical software (ver. 3.1.0).


Enjoyed this commodity? I'd exist very grateful if you'd help it spread past emailing it to a friend, or sharing it on Twitter, Facebook or Linked In.

Show me some love with the like buttons below... Thank you and delight don't forget to share and annotate beneath!!

Avez vous aimé cet article? Je vous serais très reconnaissant si vous aidiez à sa diffusion en l'envoyant par courriel à united nations ami ou en le partageant sur Twitter, Facebook ou Linked In.

Montrez-moi united nations peu d'amour avec les like ci-dessous ... Merci et n'oubliez pas, s'il vous plaît, de partager et de commenter ci-dessous!



Source: http://www.sthda.com/english/wiki/abline-r-function-an-easy-way-to-add-straight-lines-to-a-plot-using-r-software

Posted by: leclaircamigat.blogspot.com

0 Response to "How To Draw A Vertical Line In R Histogram"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel