R Advanced

How to Use “lwd” in R

The lwd in R is used to specify the width of plot lines. It is a parameter that can be set in various plotting functions, such as plot(), lines(), abline(), etc.

Syntax of lwd parameter

plot( x, y, pch = 1, cex = 1, col = 1, 
      bg = 0, lwd = 1, lty = 1, type = "p", add = FALSE )

As you can see, one of the arguments is lwd, and its value is 1.

Example

x <- c(1, 2, 3, 4, 5, 6, 7) 
y <- c(1, 8, 27, 64, 125, 216, 343) 

plot(x, y, pch=23, col = "black", bg = "yellow", lwd=1, cex=1.5)

Output

In this plot, we have passed the lwd = 1 value, and you can see that the diamond point’s border has a width of 1. If we change the lwd = 2, the width will increase.

Use the pch option to define the symbols for your plotting points. For example, from symbols 21 through 25, you can define the border color (col=) and fill color (bg=).

Various options can help you specify the color for various plot properties.

Share
Published by
Krunal Lathiya

Recent Posts

How to Convert List to Numeric in R

To convert a list to a numeric value in R, you can combine the unlist()…

1 year ago

How to Convert Double to Integer in R

To convert a double or float to an integer, you can use the "as.integer()" function.…

1 year ago

R dirname() Function

The dirname() function in R is used to extract the path to the directory from…

1 year ago

R month.abb

The month.abb is a built-in R constant, a three-letter abbreviation for the English month names. Example 1:…

1 year ago

R seq_along() Function

The seq_along() function in R is used to generate a sequence of integers along the…

1 year ago

Pi in R: Built-in Constants

Pi is a built-in R constant whose value is 3.141593. Pi is the ratio of…

1 year ago