Error in plot command - Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ

Hi,

I am new to R.

I am unable to run the plot command. I kindly request for your advise.

plot(netLV, pmeans,main = "Participant Means on\nCFA Latent Variable",

  •  ylab = "Participant Means",
    
  •  xlab = "CFA Latent Variable")
    

Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ

We don't really have enough info to help you out. Could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

1 Like
plot(netLV, pmeans,main = "Participant Means on\nCFA Latent Variable",
+      ylab = "Participant Means",
+      xlab = "CFA Latent Variable")
Error in xy.coords(x, y, xlabel, ylabel, log) : 
  'x' and 'y' lengths differ
#> Error: <text>:2:13: unexpected '='
#> 1: plot(netLV, pmeans,main = "Participant Means on\nCFA Latent Variable",
#> 2: +      ylab =
#>                ^

Created on 2019-02-18 by the reprex package (v0.2.1)

That is not reproducible because we don't know from where netLV comes from

netLV
#> Error in eval(expr, envir, enclos): object 'netLV' not found

Hi, thanks for the quick feedback. netLV is latent network score generated.

OK.... but we need to see some sample data in order to check what your problem is about, you are not providing a valid reproducible example, please read the link I gave you before and try to make one

data<-(HRS16_dataset[,1:39])
#> Error in eval(expr, envir, enclos): object 'HRS16_dataset' not found
tmfg<- TMFG (HRS16_dataset[,1:39], na.data="pairwise") $A
#> Error in TMFG(HRS16_dataset[, 1:39], na.data = "pairwise"): could not find function "TMFG"
netScores <- nams(data, tmfg, comm = facets)
#> Error in nams(data, tmfg, comm = facets): could not find function "nams"
netLV <- netScores$NetAdjScore$overall
#> Error in eval(expr, envir, enclos): object 'netScores' not found
pmeans <- scale(rowMeans(data))
#> Error in rowMeans(data): 'x' must be an array of at least two dimensions
plot(netLV, pmeans,main = "Participant Means on\nCFA Latent Variable",
     ylab = "Participant Means",
     xlab = "CFA Latent Variable")
#> Error in plot(netLV, pmeans, main = "Participant Means on\nCFA Latent Variable", : object 'netLV' not found

Created on 2019-02-19 by the reprex package (v0.2.1)

Again, you are not including the sample data in your reprex and we can´t try to figure out what your problem is, please read this link more carefully and try to make a valid reproducible example.

How does this error come about?


plot(
  x = 1:3,
  y = 1:4
)
#> Error in xy.coords(x, y, xlabel, ylabel, log): 
   'x' and 'y' lengths differ

Created on 2019-02-19 by the reprex package (v0.2.1)

The error message is pretty self-explanatory, see reprex above. Note that y in that example is of greater length than x.

If I got that error, I'd have a look at the data that went into your x and y coordinates. It's not totally clear to me what netScores$NetAdjScore$overall is and so it's hard to be of much help.
RStudio's Environment pain has a nice data explorer you can use to examine this.

A reprex would obviously be helpful too, data permitting.

Dear Andrés,

Can I share my dataset in the attachment ? Reprex works well for in-built r dataset.

That is an option but the idea is that you paste a sample of your data on a copy/paste friendly format using the datapasta package or something similar.

This blog post by Mara explains how to do it

Dear Andres,

I managed to run the reprex. Please find the codes below.

library(NetworkToolbox)

df <- data.frame(
  drecall = c(NA, NA, 6, 7, 5, NA, NA, NA, NA, 8, 5, NA, NA, NA, 3, NA,
              NA, 6, 5, 5, 9, 4, 3, 4, NA, NA, 7, 3, NA, 3, 7, 7, 4, NA,
              4, 4, NA, 4, NA, 2, 4, 7, 7, 5, 7, 5, 2, 4, NA, NA),
  orientation = c(NA, NA, 3, 4, 4, NA, NA, NA, NA, 4, 4, NA, NA, NA, 4, NA,
                  NA, 4, 3, 4, 4, 4, 3, 4, NA, NA, 3, 4, NA, 3, 4, 4, 4, NA,
                  3, 4, NA, 3, NA, 3, 3, 4, 4, 3, 4, 4, 4, 4, NA, NA),
  number = c(NA, NA, NA, 3, 2, NA, NA, NA, NA, NA, 3, NA, NA, NA, NA, NA,
             NA, NA, 2, 3, 3, NA, NA, 0, NA, NA, NA, 3, NA, NA, 2, 3, 3,
             NA, 2, NA, NA, NA, NA, NA, 1, NA, 3, NA, NA, NA, NA, NA, NA,
             NA),
  slfall = c(NA, NA, 5, 5, 5, NA, NA, NA, NA, 4, 5, NA, NA, NA, 5, NA,
             NA, 3, 5, 5, 3, 5, 5, 5, NA, NA, 5, 5, NA, 5, 5, 4, 3, NA,
             3, 4, NA, 3, NA, 5, 5, 4, 5, 5, 4, 5, 5, 2, NA, NA),
  slwake = c(NA, NA, 4, 3, 1, NA, NA, NA, NA, 3, 4, NA, NA, NA, 4, NA,
             NA, 1, 1, 2, 2, 1, 4, 1, NA, NA, 3, 1, NA, 4, 1, 3, 1, NA,
             2, 3, NA, 1, NA, 4, 4, 2, 1, 4, 4, 1, 4, 1, NA, NA),
  sltired = c(NA, NA, 4, 2, 4, NA, NA, NA, NA, 4, 4, NA, NA, NA, 1, NA,
              NA, 2, 4, 4, 2, 1, 4, 4, NA, NA, 4, 3, NA, 4, 2, 1, 4, NA,
              1, 4, NA, 1, NA, 4, 2, 4, 4, 4, 4, 4, 2, 4, NA, NA),
  slmorn = c(NA, NA, 4, 4, 2, NA, NA, NA, NA, 4, 1, NA, NA, NA, 1, NA,
             NA, 2, 4, 4, 1, 1, 4, 3, NA, NA, 2, 4, NA, 1, 4, 4, 1, NA,
             2, 4, NA, 1, NA, 1, 2, 4, 4, 4, 4, 4, 4, 4, NA, NA),
  affect = c(NA, NA, 7, 8, 8, NA, NA, NA, NA, 7, 7, NA, NA, NA, 4, NA,
             NA, 7, 8, 6, 7, 0, 8, 8, NA, NA, 8, 7, NA, 8, 5, 7, 4, NA,
             8, 8, NA, NA, NA, 8, 8, 8, 8, 8, 8, 8, 7, 7, NA, NA),
  hear = c(NA, NA, 5, 4, 3, NA, 5, 4, NA, 4, 4, NA, NA, 1, 2, NA, NA,
           3, 2, 4, 3, 2, 5, 5, 3, NA, 2, 3, 2, 3, 2, 4, 5, NA, 2, 2,
           NA, 1, NA, 3, 3, 3, 4, 5, 5, 5, 5, 3, 4, NA),
  nvision = c(NA, NA, 4, 4, 4, NA, NA, NA, NA, 5, 4, NA, NA, NA, 3, NA,
              NA, 3, 4, 5, 5, 2, 5, 5, NA, NA, 4, 4, NA, 3, 3, 4, 1, NA,
              3, 5, NA, 4, NA, 2, 3, 3, 3, 3, 4, 5, 5, 4, NA, NA)
)
tmfg<- TMFG (df, na.data="pairwise") $A
facets <-c(rep("Cognitive",3),rep("Psychological",5),rep("Sesnsory",2))
netScores <- nams(df, tmfg, comm = facets)
netLV <- netScores$NetAdjScore$overall
pmeans <- scale(rowMeans(df))
plot(netLV, pmeans)
#> Error in xy.coords(x, y, xlabel, ylabel, log): 'x' and 'y' lengths differ

Created on 2019-02-21 by the reprex package (v0.2.1)

At least one reason for this is the fact that netLV is NULL:

is(netLV)
#> [1] "NULL"             "OptionalFunction" "optionalMethod"

is(pmeans)
#> [1] "matrix"    "array"     "mMatrix"   "structure" "vector"

I can't provide a solution, because I don't know what do these variables mean, and what you're trying to plot.

Dear Yarnabrina,

I am trying to create network adjusted latent score (netLV) and participants actual means score (pmeans). I am trying to compare them.

Please see page 18/19 in the following paper https://www.researchgate.net/publication/324043454_NetworkToolbox_Methods_and_Measures_for_Brain_Cognitive_and_Psychometric_Network_Analysis_in_R

I hope this helps

netLV is NULL because you are assigning to it a value that doesn't exist.

If you look at the structure of netScores, you'll see that NetAdjScore isn't one of the list items on the first level.

library(NetworkToolbox)

df <- data.frame(
  drecall = c(NA, NA, 6, 7, 5, NA, NA, NA, NA, 8, 5, NA, NA, NA, 3, NA,
              NA, 6, 5, 5, 9, 4, 3, 4, NA, NA, 7, 3, NA, 3, 7, 7, 4, NA,
              4, 4, NA, 4, NA, 2, 4, 7, 7, 5, 7, 5, 2, 4, NA, NA),
  orientation = c(NA, NA, 3, 4, 4, NA, NA, NA, NA, 4, 4, NA, NA, NA, 4, NA,
                  NA, 4, 3, 4, 4, 4, 3, 4, NA, NA, 3, 4, NA, 3, 4, 4, 4, NA,
                  3, 4, NA, 3, NA, 3, 3, 4, 4, 3, 4, 4, 4, 4, NA, NA),
  number = c(NA, NA, NA, 3, 2, NA, NA, NA, NA, NA, 3, NA, NA, NA, NA, NA,
             NA, NA, 2, 3, 3, NA, NA, 0, NA, NA, NA, 3, NA, NA, 2, 3, 3,
             NA, 2, NA, NA, NA, NA, NA, 1, NA, 3, NA, NA, NA, NA, NA, NA,
             NA),
  slfall = c(NA, NA, 5, 5, 5, NA, NA, NA, NA, 4, 5, NA, NA, NA, 5, NA,
             NA, 3, 5, 5, 3, 5, 5, 5, NA, NA, 5, 5, NA, 5, 5, 4, 3, NA,
             3, 4, NA, 3, NA, 5, 5, 4, 5, 5, 4, 5, 5, 2, NA, NA),
  slwake = c(NA, NA, 4, 3, 1, NA, NA, NA, NA, 3, 4, NA, NA, NA, 4, NA,
             NA, 1, 1, 2, 2, 1, 4, 1, NA, NA, 3, 1, NA, 4, 1, 3, 1, NA,
             2, 3, NA, 1, NA, 4, 4, 2, 1, 4, 4, 1, 4, 1, NA, NA),
  sltired = c(NA, NA, 4, 2, 4, NA, NA, NA, NA, 4, 4, NA, NA, NA, 1, NA,
              NA, 2, 4, 4, 2, 1, 4, 4, NA, NA, 4, 3, NA, 4, 2, 1, 4, NA,
              1, 4, NA, 1, NA, 4, 2, 4, 4, 4, 4, 4, 2, 4, NA, NA),
  slmorn = c(NA, NA, 4, 4, 2, NA, NA, NA, NA, 4, 1, NA, NA, NA, 1, NA,
             NA, 2, 4, 4, 1, 1, 4, 3, NA, NA, 2, 4, NA, 1, 4, 4, 1, NA,
             2, 4, NA, 1, NA, 1, 2, 4, 4, 4, 4, 4, 4, 4, NA, NA),
  affect = c(NA, NA, 7, 8, 8, NA, NA, NA, NA, 7, 7, NA, NA, NA, 4, NA,
             NA, 7, 8, 6, 7, 0, 8, 8, NA, NA, 8, 7, NA, 8, 5, 7, 4, NA,
             8, 8, NA, NA, NA, 8, 8, 8, 8, 8, 8, 8, 7, 7, NA, NA),
  hear = c(NA, NA, 5, 4, 3, NA, 5, 4, NA, 4, 4, NA, NA, 1, 2, NA, NA,
           3, 2, 4, 3, 2, 5, 5, 3, NA, 2, 3, 2, 3, 2, 4, 5, NA, 2, 2,
           NA, 1, NA, 3, 3, 3, 4, 5, 5, 5, 5, 3, 4, NA),
  nvision = c(NA, NA, 4, 4, 4, NA, NA, NA, NA, 5, 4, NA, NA, NA, 3, NA,
              NA, 3, 4, 5, 5, 2, 5, 5, NA, NA, 4, 4, NA, 3, 3, 4, 1, NA,
              3, 5, NA, 4, NA, 2, 3, 3, 3, 3, 4, 5, 5, 4, NA, NA)
)
tmfg<- TMFG (df, na.data="pairwise") $A
facets <-c(rep("Cognitive",3),rep("Psychological",5),rep("Sesnsory",2))
netScores <- nams(df, tmfg, comm = facets)
netLV <- netScores$NetAdjScore$overall
netScores$NetAdjScores
#> NULL

str(netScores)
#> List of 4
#>  $ Standardized  :'data.frame':  50 obs. of  4 variables:
#>   ..$ Cognitive    : num [1:50] NA NA NA 1.054 -0.223 ...
#>   ..$ Psychological: num [1:50] NA NA NA 0.976 0.132 ...
#>   ..$ Sesnsory     : num [1:50] NA NA NA 0.6025 -0.0848 ...
#>   ..$ overall      : num [1:50] NA NA NA 1.3324 -0.0929 ...
#>  $ Unstandardized:'data.frame':  50 obs. of  4 variables:
#>   ..$ Cognitive    : num [1:50] NA NA NA 5.03 3.95 ...
#>   ..$ Psychological: num [1:50] NA NA NA 4.67 4.1 ...
#>   ..$ Sesnsory     : num [1:50] NA NA NA 4.06 3.56 ...
#>   ..$ overall      : num [1:50] NA NA NA 4.71 3.97 ...
#>  $ CommItems     :'data.frame':  3 obs. of  2 variables:
#>   ..$ Community: Factor w/ 3 levels "Cognitive","Psychological",..: 1 2 3
#>   ..$ Items    : Factor w/ 3 levels "drecall, orientation, number",..: 1 3 2
#>  $ CommCor       : num [1:4, 1:4] 1 NA NA NA NA 1 NA NA NA NA ...
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : chr [1:4] "Cognitive" "Psychological" "Sesnsory" "overall"
#>   .. ..$ : chr [1:4] "Cognitive" "Psychological" "Sesnsory" "overall"

Created on 2019-02-21 by the reprex package (v0.2.1.9000)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.