Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Creating qqnorm plots over mulitple with correct column name

I have made this for loop to make create qqnorms for all specified columns. However it doesn’t output the names correctly. I need the column name to align with the correct plot.

par(mfrow = c(3,2))
loop.vector <- 3:7 # designate columns for qqnorms
colName <- names(Final_data[loop.vector]) # gets column name
for (i in loop.vector) {
    x <- Final_data[, i]
    qqnorm(x, main = paste(colName))
}

Outputs:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is what I need:

enter image description here

>Solution :

There is a typo in your loop. Might be easier to use

par(mfrow = c(3, 2))
lapply(names(mtcars)[3:7], \(i) qqnorm(mtcars[[i]], main = i))

where we use mtcars as toy data.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading