Search code examples
rkernel-density

Increasing the line thickness in R


I am trying to make a density plot with 2 variables but I need the lines to be thicker. I have used this command:

    >print(plot(density(x,na.rm = T),col="blue",lwd=3,main="Text",cex.main=1.2))

    >lines(density(y,na.rm = T),col="purple",lwd=3)

Although it did thicken the line, below the command it shows: NULL What am I doing wrong? Thanks in advance.


Solution

  • No need for print. Just do:

    # Sample data
    set.seed(2017);
    x <- rnorm(100, 2);
    y <- rnorm(100, 2, 3);
    
    plot(density(x, na.rm = T), col = "blue", lwd = 3, main = "Text", cex.main = 1.2);
    lines(density(y, na.rm = T), col = "purple", lwd = 3)
    

    enter image description here