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

rbind() Function: Binding Rows in R

The rbind() function combines R objects, such as vectors, matrices, or data frames, by rows.…

3 hours ago

as.numeric(): Converting to Numeric Values in R

The as.numeric() function in R converts valid non-numeric data into numeric data. What do I…

1 week ago

Calculating Natural Log using log() Function in R

The log() function calculates the natural logarithm (base e) of a numeric vector. By default,…

2 weeks ago

Dollar Sign ($ Operator) in R

In R, you can use the dollar sign ($ operator)  to access elements (columns) of…

4 weeks ago

Calculating Absolute Value using abs() Function in R

The abs() function calculates the absolute value of a numeric input, returning a non-negative (only…

1 month ago

Printing an Output of a Program in R

When working with R in an interactive mode, you don't need to use any functions…

1 month ago