Line types in R : lty

The different line types available in R are shown in the figure hereafter. The argument lty can be used to specify the line type. To change line width, the argument lwd can be used.

The different line types

Line types in R

The function used to generate this figure is provided at the end of this document.

line type (lty) can be specified using either text (“blank”, “solid”, “dashed”, “dotted”, “dotdash”, “longdash”, “twodash”) or number (0, 1, 2, 3, 4, 5, 6). Note that lty = “solid” is identical to lty=1.


# Solid line (by default)
plot(1:10, 1:10, type="l")
# Use dashed line type
plot(1:10, 1:10, type="l", lty=2)
# Change line width
plot(1:10, 1:10, type="l", lty=2, lwd=3)

plot of chunk exampleplot of chunk exampleplot of chunk example

By default lty = 1

R script to generate a plot of line types

Use the following R function to display a graph of the line types available in R :

#Line types
  par(font=2, mar=c(0,0,0,0))
  plot(1, pch="", ylim=c(0,6), xlim=c(0,0.7),  axes=FALSE,xlab="", ylab="")
  for(i in 0:6) lines(c(0.3,0.7), c(i,i), lty=i, lwd=3)
  text(rep(0.1,6), 0:6, labels=c("0.'blank'", "1.'solid'", "2.'dashed'", "3.'dotted'",
                                 "4.'dotdash'", "5.'longdash'", "6.'twodash'"))
  par(mar=oldPar$mar,font=oldPar$font )


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

Want to Learn More on R Programming and Data Science?

Follow us by Email

by FeedBurner

On Social Networks:

 Get involved :
  Click to follow us on and Google+ :   
  Comment this article by clicking on "Discussion" button (top-right position of this page)
  Sign up as a member and post news and articles on STHDA web site.
This page has been seen 40121 times