Lines (or curves) can be customized in R in several ways with different graphical parameters. The graphical parameters of this guide can be used with several functions such as
There exist seven styles, specified by either their integer or character string. The default value is 1 (
You can also specify patterns with strings of 2, 4, 6, or 8 characters (hexadecimal, characters, 1–9 and a–f) to create custom lines.
"55" creates a pattern of 5 units followed by 5 blank units. Units are proportional to
The width of the lines can be set using the
lwd argument. The default value is 1.
You can set any positive value in order to create the desired line.
When creating a plot with the
matplot or when adding new lines with
matlines functions you can create different types of line plots with the
type argument. Defaults to
|“b”||Lines and points|
|“c”||Lines without the
part of the points
|“o”||Lines and points
(first line horizontal)
(first line vertical)
You can customize the colors of the lines with the
col argument. See the colors section to know more about the available colors.
data <- matrix(1:40, ncol = 8) matplot(data, type = "l", col = 1:10, lty = 1, lwd = 2)
💡 Tip: combine line types and colors to create custom patterns.
curve(cos, -4, 4, col = 4, lwd = 7, lty = 1) curve(cos, -4, 4, col = 2, lwd = 7, lty = "aa", add = TRUE)
There are three different line end styles, that can be selected with the
lend argument by either their integer (0, 1, 2) or character string (
"square", respectively). Defaults to 0.
You can also select between different line join styles with the
ljoin argument, which possible values are 0 or
"round" (default), 1 or
"mitre" and 2 or
Note that the red lines represent the actual start and end of the data.