0

I'm new to r and am struggling to create plots (to test linearity and normal distribution assumptions) with the following functions below. When I run these functions, I get the correct results in the console, but the plot does not appear in 'Plots' at all/or does not appear with labels.

1 I have created random chi-square values, run a fake regression with these and produced studentized residuals based on this fake regression. I then tried to run a qqplot with an integrated line but the plot appears without a labelled x or y axis and no title (e.g., "Theoretical Quantiles" does not appear on the x axis in the plot)

random = rchisq(nrow(vdata_clean1), 7)

fake = lm(random~., data = vdata_clean1)

standardized = rstudent(fake)

qqnorm(standardized)

abline(0,1)

(or)

qqnorm(standardized, main = "Normal Q-Q Plot", xlab = "Theoretical    
Quantiles", ylab = "Sample Quantiles", plot.it = TRUE, datax = FALSE,    
distribution)

2 When I run this function, no plots or graphs appear at all.

mvn(vdata_clean1, mvnTest = c("mardia"), 
covariance = TRUE, tol = 1e-25, alpha = 0.5, scale = FALSE,
desc = TRUE, transform = "none", R = 1000,  univariateTest = c("SW"),
univariatePlot = c("qq"), multivariatePlot = c("qqplot"),
multivariateOutlierMethod = "none", bc = FALSE, bcType = "rounded",
showOutliers = FALSE, showNewData = FALSE)

These are the packages I have installed:

install.packages("lavaan")
library(lavaan)
install.packages("semPlot")
library(semPlot)
install.packages("semTools")
library(semTools)
install.packages("MVN")
library(MVN)
install.packages("mvtnorm")
library(mvtnorm)
install.packages("ggplot2")
library(ggplot2)
install.packages("qgraph")
library(qgraph)
install.packages("GGally")
library(GGally)

This is a sample of my data:

head(vdata_clean1) A tibble: 6 x 15 ILproto_1 ILproto_2 ILproto_3 ILproto_4 ILadvance_1 ILadvance_2
ILadvance_3 ILadvance_4 ILentre_1 ILentre_2
1 2 [2] 2 [2] 6 [6] 2 [2] 2 [2] 2 [2] 2 [2]
2 [2] 2 [2] 2 [2] 2 5 [5] 5 [5] 5 [5] 5 [5] 5 [5] 4 [4] 6 [6]
4 [4] 5 [5] 5 [5] 3 6 [6] 5 [5] 5 [5] 6 [6] 5 [5] 4 [4] 5 [5]
6 [6] 6 [6] 5 [5] 4 2 [2] 3 [3] 4 [4] 5 [5] 5 [5] 6 [6] 7
[Strongl… 6 [6] 4 [4] 5 [5] 5 3 [3] 5 [5] 4 [4] 5 [5] 3 [3] 5 [5] 5 [5]
3 [3] 3 [3] 4 [4] 6 7 [Stron… 4 [4] 5 [5] 4 [4] 5 [5] 3 [3] 5 [5]
3 [3] 5 [5] 3 [3] # … with 5 more variables: ILentre_3 , ILentre_4 ,
ILimpres_1 , ILimpres_2 , # ILimpres_3

> dput(vdata_clean1)
structure(list(ILproto_1 = structure(c(2, 5, 6, 2, 3, 7, 1, 5, 
4, 6, 4, 3, 5, 1, 7, 4, 4, 4, 2, 4, 4, 5, 2, 6, 6, 6, 7, 4, 4, 
4, 4, 5, 4, 6, 6, 3, 4, 7, 5, 1, 6, 6, 2, 3, 5, 7, 5, 3, 7, 6, 
6, 7, 7, 7, 4, 5, 4, 4, 7, 5, 5, 6, 5, 6, 6, 5, 7, 5, 3, 4, 5, 
4, 7, 3, 6, 7, 4, 7, 5, 5, 7, 5, 4, 7, 2, 7, 6, 7, 3, 6, 7, 5, 
5, 7, 3, 6, 6, 6, 7, 5), label = "ILproto_1", format.spss = "F40.0",    
display_width = 12L, class = "haven_labelled", labels = c(`Strongly    
disagree 1` = 1, `2` = 2, `3` = 3, `4` = 4, `5` = 5, `6` = 6, `Strongly   
agree 7` = 7)),
ILproto_2 = structure(c(2, 5, 5, 3, 5, 4, 1, 6, 4, 7, 4, 2, 4, 1, 7, 4, 
4, 5, 2, 4, 4, 5, 2, 6, 6, 6, 7, 4, 4, 4, 4, 5, 
4, 5, 6, 3, 5, 7, 4, 1, 6, 6, 2, 1, 5, 7, 5, 3, 7, 6, 6, 7, 7, 
7, 3, 5, 4, 4, 7, 5, 5, 6, 5, 6, 6, 4, 7, 5, 4, 4, 5, 3, 7, 3, 
7, 6, 4, 7, 5, 5, 6, 5, 4, 7, 2, 7, 6, 7, 3, 6, 7, 5, 5, 7, 3, 
6, 6, 5, 7, 5), label = "ILproto_2", format.spss = "F40.0",     
display_width = 11L, class = "haven_labelled", labels = c(`Strongly     
disagree 1` = 1, `2` = 2, `3` = 3, `4` = 4, `5` = 5, `6` = 6, `Strongly     
agree 7` = 7)),
ILproto_3 = structure(c(6, 5, 5, 4, 4, 5, 1, 6, 5, 7, 4, 
3, 4, 1, 7, 4, 4, 5, 3, 4, 4, 5, 2, 6, 4, 6, 7, 4, 5, 4, 3, 4, 
4, 6, 6, 3, 4, 7, 5, 1, 6, 6, 5, 2, 6, 7, 6, 4, 7, 6, 6, 7, 7, 
5, 3, 6, 4, 4, 7, 5, 5, 6, 5, 6, 6, 6, 7, 6, 3, 4, 5, 4, 7, 3, 
7, 7, 4, 7, 4, 5, 5, 5, 7, 7, 2, 7, 6, 7, 4, 6, 7, 7, 5, 7, 3, 
6, 6, 6, 7, 5), label = "ILproto_3", format.spss = "F40.0", class =     
"haven_labelled", labels = c(`Strongly disagree
1` = 1, `2` = 2, `3` = 3, `4` = 4, `5` = 5, `6` = 6, `Strongly agree
7` = 7)), ILproto_4 = structure(c(2, 5, 6, 5, 5, 4, 1, 5, 5, 7, 4, 1,     
5, 1, 7, 5, 4, 5, 2, 4, 4, 5, 2, 6, 5, 6, 7, 4, 4, 5, 5, 4, 
4, 6, 6, 3, 4, 7, 5, 1, 6, 6, 2, 2, 6, 7, 7, 5, 7, 6, 6, 7, 7, 
5, 4, 6, 4, 4, 7, 5, 5, 6, 4, 6, 6, 5, 7, 6, 5, 5, 5, 3, 7, 3, 
5, 6, 5, 7, 4, 5, 4, 5, 7, 7, 2, 7, 6, 7, 3, 6, 7, 5, 5, 7, 3, 
6, 6, 5, 7, 6), label = "ILproto_4", format.spss = "F40.0",     
display_width = 10L, class = "haven_labelled", labels = c(`Strongly     
disagree 1` = 1, `2` = 2, `3` = 3, `4` = 4, `5` = 5, `6` = 6, `Strongly            
agree 7` = 7)), ILadvance_1 = structure(c(2, 5, 5, 5, 3, 5, 3, 6, 4, 7,     
2, 4, 6, 1, 7, 4, 4, 4, 3, 4, 4, 6, 2, 5, 6, 6, 5, 4, 4, 4, 4, 6, 
4, 6, 6, 4, 4, 7, 5, 1, 6, 6, 2, 2, 5, 7, 7, 7, 7, 6, 6, 6, 7, 
1, 4, 6, 4, 2, 7, 2, 6, 6, 7, 6, 6, 3, 7, 6, 4, 4, 5, 4, 7, 3, 
7, 7, 5, 7, 4, 6, 4, 5, 7, 7, 2, 7, 7, 7, 5, 7, 7, 7, 5, 7, 4, 
5, 7, 6, 7, 4), label = "Iladvance_1", format.spss = "F40.0",         
display_width = 11L, class = "haven_labelled", labels = c(`Strongly     
disagree 1` = 1, `2` = 2, `3` = 3, `4` = 4, `5` = 5, `6` = 6, `Strongly 
agree 7` = 7)),
ILadvance_2 = structure(c(2, 4, 4, 6, 5, 3, 4, 6, 5, 7, 4, 
2, 4, 1, 7, 4, 4, 4, 3, 4, 4, 6, 2, 5, 6, 6, 5, 4, 4, 3, 4, 4, 
4, 6, 6, 5, 4, 7, 6, 1, 6, 6, 2, 2, 6, 7, 6, 6, 7, 6, 6, 6, 7, 
1, 5, 6, 4, 4, 7, 4, 6, 6, 7, 6, 6, 4, 7, 6, 4, 4, 5, 3, 7, 3, 
6, 6, 4, 7, 4, 6, 2, 5, 7, 7, 2, 7, 7, 7, 5, 7, 7, 7, 4, 7, 4, 
6, 7, 5, 7, 4), label = "Iladvance_2", format.spss = "F40.0",     
display_width = 9L, class = "haven_labelled", labels = c(`Strongly         
disagree 1` = 1, `2` = 2, `3` = 3, `4` = 4, `5` = 5, `6` = 6, `Strongly     
agree 7` = 7)), ILadvance_3 = structure(c(2, 6, 5, 7, 5, 5, 4, 5, 5, 6, 
4, 2, 4, 1, 7, 4, 4, 4, 3, 4, 4, 6, 2, 5, 6, 6, 5, 4, 4, 3, 4, 6, 
4, 6, 6, 4, 4, 7, 5, 1, 6, 6, 4, 2, 5, 7, 7, 7, 7, 6, 6, 6, 7, 
1, 4, 6, 4, 4, 7, 4, 6, 6, 7, 6, 6, 5, 7, 6, 5, 4, 5, 4, 7, 3, 
7, 7, 4, 7, 5, 6, 3, 5, 7, 7, 2, 7, 7, 7, 5, 7, 7, 7, 6, 7, 4, 
7, 7, 5, 7, 5), label = "Iladvance_3", format.spss = "F40.0", 
display_width = 11L, class = "haven_labelled", labels = c(`Strongly 
disagree 1` = 1, `2` = 2, `3` = 3, `4` = 4, `5` = 5, `6` = 6, `Strongly     
agree 7` = 7)), ILadvance_4 = structure(c(2, 4, 6, 6, 3, 3, 4, 5, 4, 7,     
4, 2, 4, 1, 7, 4, 4, 4, 3, 4, 4, 6, 2, 5, 6, 6, 5, 4, 4, 5, 3, 4, 
4, 6, 6, 4, 4, 7, 5, 1, 6, 6, 4, 1, 6, 7, 7, 7, 7, 6, 6, 6, 7, 
1, 4, 6, 4, 4, 7, 4, 6, 6, 7, 6, 7, 4, 7, 5, 5, 4, 5, 3, 7, 3, 
7, 6, 5, 7, 5, 6, 4, 5, 7, 7, 2, 7, 7, 7, 5, 7, 7, 7, 6, 7, 4, 
7, 7, 6, 7, 5), label = "Iladvance_4", format.spss = "F40.0",     
display_width = 9L, class = "haven_labelled", labels = c(`Strongly 
disagree 1` = 1, `2` = 2, `3` = 3, `4` = 4, `5` = 5, `6` = 6, `Strongly     
agree 7` = 7)),  row.names = c(NA, -100L), class = c("tbl_df", "tbl",     
"data.frame"))
....entre_1, entre_2, entre_3, entre_1, impres_1, impres_2_, impres_3

I am grateful for any help on this :)

Vicci
  • 35
  • 1
  • 7
  • if possible, could you provide a sample of your data to reproduce this (vdata_clean1) https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Ben Jul 10 '19 at 13:33
  • Thank you for the advice - I've tried to upload a sample from my data, is this what you had in mind? – Vicci Jul 10 '19 at 14:25
  • thanks @Vicci - though this data set appears somewhat complex (dput only included a portion of vdata_clean1) - can you share the minimum amount of data to reproduce the problem such as a subset of the data? if you can feel free to edit your question further with the update. – Ben Jul 10 '19 at 17:39

0 Answers0