How To Draw Line On Histogram In R
abline R office : An easy fashion to add directly lines to a plot using R software
- Add a vertical line
- Add together an horizontal line
- Add regression line
- Infos
The aim of this tutorial is to show you how to add one or more straight lines to a graph using R statistical software. The R function abline() tin can be used to add together vertical, horizontal or regression lines to a graph.
A simplified format of the abline() function is :
abline(a=Nada, b=Goose egg, h=Goose egg, five=Aught, ...) - a, b : single values specifying the intercept and the slope of the line
- h : the y-value(s) for horizontal line(southward)
- v : the 10-value(s) for vertical line(south)
Add together a vertical line
The simplified format is :
abline(v = y) Information technology draws a vertical line on the current plot at the specified 'y' coordinates.
# get-go instance : Add together one line plot(cars) abline(v=15, col="blue") # second example : add two lines # change line colors, sizes and types plot(cars) abline(v=c(15,20), col=c("blue", "red"), lty=c(1,2), lwd=c(one, 3)) # third example fix.seed(1234); mydata<-rnorm(200) hist(mydata, col="lightblue") abline(five = hateful(mydata), col="ruddy", lwd=3, lty=2)
Note that, line types (lty) and line width (lwd) are explained hither.
Add an horizontal line
The simplified format is :
abline(h = x) Information technology draws an horizontal line on the current plot at the specified '10' coordinates.
plot(cars) abline(h=40, col="blue")
Add regression line
lm() part is used to fit linear models.
par(mgp=c(ii,1,0), mar=c(3,3,ane,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],1)) # plot plot(cars, main=eq) abline(reg, col="blue")
Infos
This assay has been performed using R statistical software (ver. iii.ane.0).
Enjoyed this commodity? I'd be very grateful if yous'd assistance it spread past emailing it to a friend, or sharing it on Twitter, Facebook or Linked In.
Prove me some dear with the like buttons below... Thank yous and please don't forget to share and comment below!!
Avez vous aimé cet article? Je vous serais très reconnaissant si vous aidiez à sa diffusion en 50'envoyant par courriel à un ami ou en le partageant sur Twitter, Facebook ou Linked In.
Montrez-moi un peu d'amour avec les like ci-dessous ... Merci et n'oubliez pas, southward'il vous plaît, de partager et de commenter ci-dessous!
Recommended for You!
Recommended for you
This section contains best data scientific discipline and cocky-development resources to help you on your path.
Desire to Learn More on R Programming and Information Scientific discipline?
Follow united states of america by Email
On Social Networks:
Get involved :
Click to follow us on Facebook and Google+ :
Comment this article by clicking on "Discussion" button (top-correct position of this page)
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: brownthisees.blogspot.com

0 Response to "How To Draw Line On Histogram In R"
Post a Comment