Written and maintained by CASRAI Editorial Board
Last updated
lwd in R is the graphical parameter that sets line width. Its default is 1, it takes a positive number, and larger values draw thicker lines. On the pdf() device one unit is 1/96 inch, so lwd = 1 is about 0.75 point. This guide covers lwd (also searched as “lwd r”) in base R graphics and the separate linewidth argument in ggplot2, whose unit is not the same.
What lwd is used for in research
Line width is how a figure keeps a fitted line visible against data points, separates a reference line from a data series, and stays legible after a journal shrinks the figure. lwd sets it for lines drawn with plot(), lines(), abline(), segments() and related base-graphics calls. It sits beside lty (line type) and col (colour), and the three are usually set together. For the plot types themselves, see plotting a line in R and scatterplots in R.
Install or access (official source only)
lwd is part of the graphics package that ships with R, so nothing extra is installed. R itself is downloaded from CRAN, the Comprehensive R Archive Network, at cran.r-project.org, which offers builds for Windows, macOS and Linux. The ggplot2 package is installed from CRAN inside R with install.packages("ggplot2").
Step-by-step: set line width
1. Pass lwd to a plotting call
- Draw a line plot with a thicker line:
plot(x, y, type = "l", lwd = 3). - Add a second line with a different width:
lines(x, y2, lwd = 1.5). - Combine with type and colour:
lines(x, y2, lty = 2, lwd = 2, col = "grey40").
The R documentation for par defines lwd as “the line width, a positive number, defaulting to 1”. Because it is not one of the parameters restricted to par() alone, it can be given directly to plotting calls as above.
2. Set a default for later plots with par()
par(lwd = 2) changes the default width for lines drawn afterwards on the same device. Setting it inside a single call affects only that call.
3. Give different widths to different lines
For lines() and segments(), lwd can be a vector, which is recycled over the lines drawn. For example, segments(x0, y0, x1, y1, lwd = c(1, 3)) alternates between widths 1 and 3.
4. In ggplot2, use linewidth instead
ggplot2 geoms such as geom_line() and geom_path() take linewidth and linetype as aesthetics: ggplot(df, aes(x, y)) + geom_line(linewidth = 1.5).
Output and how to read it
What one unit of lwd means
According to the grDevices help for pdf(), line widths controlled by par(lwd = ) are multiples of 1/96 inch, a minimum of 0.01 is enforced, and multiples below 1 are allowed. So lwd = 2 is 2/96 inch, about 1.5 points, on a PDF. The R documentation also states that on-screen and other devices interpret width in a device-specific way, so the same number can look slightly different on a PNG, on screen and in a PDF.
Base lwd versus ggplot2 linewidth
The two arguments use different units. The ggplot2 specification states that, due to a historical error, the unit of linewidth is roughly 0.75 mm, and that it was left unchanged because making it exactly 1 mm would change a very large number of existing plots. The same number in lwd and in linewidth therefore does not give the same drawn width; when moving a figure between the two systems, compare the output rather than copying the value.
Related line settings
| Setting | Values documented for par() |
|---|---|
lty |
0 blank, 1 solid, 2 dashed, 3 dotted, 4 dotdash, 5 longdash, 6 twodash |
lend (line end) |
0 or “round” (default), 1 or “butt”, 2 or “square” |
ljoin (line join) |
0 or “round” (default), 1 or “mitre”, 2 or “bevel” |
With thick lines, the lend and ljoin choices become easier to see, so set them explicitly when the exact look of line ends and corners matters.
Troubleshooting
Why is lwd below 1 not thinner?
The par documentation says the interpretation of line width is device-specific and that some devices do not implement widths less than one. Check the saved file on the device you will publish from, and if a thin line is needed, test on a PDF device, where multiples less than 1 are allowed.
Why does a very thin dashed line look solid?
The pdf() documentation notes that at very small line widths the line type may be forced to solid. Increase lwd slightly if a dashed or dotted pattern disappears.
Why does lwd = 0 behave differently across devices?
The documentation states that the interpretation of 0 is device-specific, so use a small positive value instead.
Why does lwd do nothing in my ggplot?
ggplot2 layers use linewidth. Some older tutorials use a size argument for lines; check the geom reference for your installed ggplot2 version and use the argument it documents for line thickness.
Free alternatives
| Approach | Argument | Unit and notes (from the R and ggplot2 documentation) |
|---|---|---|
| Base R graphics | lwd |
Default 1; multiples of 1/96 inch on pdf(); device-specific elsewhere |
| ggplot2 | linewidth |
Roughly 0.75 mm per unit |
Both are free and open source. For other plot types that use these arguments, see ggplots in R and histograms in R.
FAQ
What does lwd stand for in R?
Line width. It is the graphical parameter that sets how thick lines are drawn, defaulting to 1.
What is the default lwd in R?
1. The documentation defines it as a positive number with a default of 1.
Can lwd be a decimal?
Yes. It is a positive number, and on pdf() multiples less than 1 are allowed, down to a minimum of 0.01.
Is lwd the same as linewidth in ggplot2?
No. They are different arguments in different systems, and ggplot2’s unit is roughly 0.75 mm.
Sources
- R graphics package, par: Set or Query Graphical Parameters (checked 2026-10-29).
- R grDevices package, pdf: PDF Graphics Device (checked 2026-10-29).
- ggplot2, Aesthetic specifications (checked 2026-10-29).
- ggplot2, geom_path reference (checked 2026-10-29).
- CRAN, The Comprehensive R Archive Network (checked 2026-10-29).







