R Charts

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

R length(): Vector, List, Matrix, Array, Data Frame, String

Before executing an operation on an object, it is advisable to check its length, as…

15 hours ago

How to Round Numbers in R

Rounding is a process of approximating a number to a shorter, simpler, and more interpretable…

2 days ago

Adding Single or Multiple Columns to Data Frame in R

Whether you want to add new data to your existing datasets or create new variables…

4 days ago

sqrt() Function: Calculate Square Root in R

The square root of a number is a value that is multiplied by itself, giving…

5 days ago

How to Remove Duplicate Rows from DataFrame in R

Duplicate rows refer to all the values across all columns that are the same in…

6 days ago

How to Remove NA From Vector in R

A vector is a data structure that holds the same type of data. When working…

1 week ago