1

平行座標プロットを作成する必要があり、lattice::parallellplotそのために使用しようとしています。現在、data.frame で変数を見つけることができないようです。

df <- structure(list(Patient = structure(c(1L, 1L, 2L, 2L, 3L, 3L), .Label = c("K1", 
"K10", "K11", "K12", "K13", "K14", "K3", "K5", "K6", "K7", "K8", 
"K9", "M1", "M10", "M11", "M12", "M13", "M14", "M15", "M16", 
"M17", "M18", "M3", "M4", "M5", "M6", "M7", "M8", "M9", "P11", 
"P14", "P15", "P17", "P19", "P20", "P21", "P22", "P24", "P25zi", 
"P26zi", "P27zi", "P28zi", "P29zi", "P30zi", "P31zi", "P32zi", 
"P33zi", "P34zi", "P35zi", "P36zi", "P37zi", "P38zi", "P39zi", 
"P40zi", "P42zi", "P43zi", "P44zi", "P45zi", "P47zi", "P48zi", 
"P49zi", "P6"), class = "factor"), Session = c("Control", "Control", 
"Control", "Control", "Control", "Control"), Stimulation = structure(c(1L, 
1L, 1L, 1L, 1L, 1L), .Label = c("Control", "Pre-op", "Stim OFF", 
"Stim ON"), class = "factor"), Medication = structure(c(1L, 1L, 
1L, 1L, 1L, 1L), .Label = c("Control", "Med OFF", "Med ON"), class = "factor"), 
    Pace = c("Fast", "Self paced", "Fast", "Self paced", "Fast", 
    "Self paced"), Task = c("AMR", "AMR", "AMR", "AMR", "AMR", 
    "AMR"), rpvi = c(0.0182795199284812, 0.0663539828711965, 
    0.0341240824873636, 0.12187724470919, 0.072604166062397, 
    0.173523783116511), npvi = c(13.3513362238, 18.2878243201769, 
    14.2017869466867, 30.4704307031096, 27.7354960871263, 47.2650462416463
    ), cov = c(0.149873573597108, 0.161675840793806, 0.128829768483374, 
    0.248221179697023, 0.263336212564805, 0.411141115364702), 
    PatientGroup = c("Normal control", "Normal control", "Normal control", 
    "Normal control", "Normal control", "Normal control")), .Names = c("Patient", 
"Session", "Stimulation", "Medication", "Pace", "Task", "rpvi", 
"npvi", "cov", "PatientGroup"), vars = list(Patient, Session, 
    Stimulation, Medication, Pace), drop = TRUE, row.names = c(NA, 
6L), class = c("grouped_df", "tbl_df", "tbl", "data.frame"))
> latice:parallelplot
> head(df)
Patient Session Stimulation Medication       Pace Task       rpvi     npvi       cov   PatientGroup
1      K1 Control     Control    Control       Fast  AMR 0.01827952 13.35134 0.1498736 Normal control
2      K1 Control     Control    Control Self paced  AMR 0.06635398 18.28782 0.1616758 Normal control
3     K10 Control     Control    Control       Fast  AMR 0.03412408 14.20179 0.1288298 Normal control
4     K10 Control     Control    Control Self paced  AMR 0.12187724 30.47043 0.2482212 Normal control
5     K11 Control     Control    Control       Fast  AMR 0.07260417 27.73550 0.2633362 Normal control
6     K11 Control     Control    Control Self paced  AMR 0.17352378 47.26505 0.4111411 Normal Control
> parallelplot(nPVI | PatientGroup,data=df)
Error in parallelplot(npvi | PatientGroup, data = df) : 
  object 'npvi' not found

関数がparallelplotデータ フレーム内の列を見つけられないのはなぜですか?

セッションに関する Somoe 情報:

> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)

locale:
[1] sv_SE.UTF-8/sv_SE.UTF-8/sv_SE.UTF-8/C/sv_SE.UTF-8/sv_SE.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_1.0.0   GGally_0.4.8    lattice_0.20-29

loaded via a namespace (and not attached):
 [1] colorspace_1.2-4 digest_0.6.4     grid_3.1.0       gtable_0.1.2     MASS_7.3-34      munsell_0.4.2    plyr_1.8.1       proto_0.3-10     Rcpp_0.11.2      reshape_0.8.5   
[11] reshape2_1.4     scales_0.2.4     stringr_0.6.2    tools_3.1.0     
> searchpaths()
 [1] ".GlobalEnv"                                                               "/Library/Frameworks/R.framework/Versions/3.1/Resources/library/ggplot2"  
 [3] "/Users/frkkan96/Library/R/3.1/library/GGally"                             "/Library/Frameworks/R.framework/Versions/3.1/Resources/library/lattice"  
 [5] "tools:rstudio"                                                            "/Library/Frameworks/R.framework/Versions/3.1/Resources/library/stats"    
 [7] "/Library/Frameworks/R.framework/Versions/3.1/Resources/library/graphics"  "/Library/Frameworks/R.framework/Versions/3.1/Resources/library/grDevices"
 [9] "/Library/Frameworks/R.framework/Versions/3.1/Resources/library/utils"     "/Library/Frameworks/R.framework/Versions/3.1/Resources/library/datasets" 
[11] "/Library/Frameworks/R.framework/Versions/3.1/Resources/library/methods"   "Autoloads"                                                               
[13] "/Library/Frameworks/R.framework/Resources/library/base" 
4

1 に答える 1

1

何らかの理由でparallelplot、非常に奇妙な数式構文があります。実際には、式の右側として渡される matrix/data.frame が必要です。また、この行列には少なくとも 2 つの列が必要です。平行プロットの線は、これらの値の間に引かれます。

しかし、まず第一に、あなたが投稿しdfたのは非標準のdata.frameのようで、どういうわけか「grouped_df」というクラスを取得したため、どのように名前を付けたのかわかりません。ここでは、より標準的な data.frame に単純化しました

df <- structure(list(Patient = structure(c(1L, 1L, 2L, 2L, 3L, 3L), .Label = c("K1", 
"K10", "K11", "K12", "K13", "K14", "K3", "K5", "K6", "K7", "K8", 
"K9", "M1", "M10", "M11", "M12", "M13", "M14", "M15", "M16", 
"M17", "M18", "M3", "M4", "M5", "M6", "M7", "M8", "M9", "P11", 
"P14", "P15", "P17", "P19", "P20", "P21", "P22", "P24", "P25zi", 
"P26zi", "P27zi", "P28zi", "P29zi", "P30zi", "P31zi", "P32zi", 
"P33zi", "P34zi", "P35zi", "P36zi", "P37zi", "P38zi", "P39zi", 
"P40zi", "P42zi", "P43zi", "P44zi", "P45zi", "P47zi", "P48zi", 
"P49zi", "P6"), class = "factor"), Session = c("Control", "Control", 
"Control", "Control", "Control", "Control"), Stimulation = structure(c(1L, 
1L, 1L, 1L, 1L, 1L), .Label = c("Control", "Pre-op", "Stim OFF", 
"Stim ON"), class = "factor"), Medication = structure(c(1L, 1L, 
1L, 1L, 1L, 1L), .Label = c("Control", "Med OFF", "Med ON"), class = "factor"), 
    Pace = c("Fast", "Self paced", "Fast", "Self paced", "Fast", 
    "Self paced"), Task = c("AMR", "AMR", "AMR", "AMR", "AMR", 
    "AMR"), rpvi = c(0.0182795199284812, 0.0663539828711965, 
    0.0341240824873636, 0.12187724470919, 0.072604166062397, 
    0.173523783116511), npvi = c(13.3513362238, 18.2878243201769, 
    14.2017869466867, 30.4704307031096, 27.7354960871263, 47.2650462416463
    ), cov = c(0.149873573597108, 0.161675840793806, 0.128829768483374, 
    0.248221179697023, 0.263336212564805, 0.411141115364702), 
    PatientGroup = c("Normal control", "Normal control", "Normal control", 
    "Normal control", "Normal control", "Normal control")), .Names = c("Patient", 
"Session", "Stimulation", "Medication", "Pace", "Task", "rpvi", 
"npvi", "cov", "PatientGroup"), row.names = c(NA, 
6L), class = "data.frame")

OK、これで を呼び出す準備ができましたparallelplot。繰り返しますが、data.frame が必要で、少なくとも 2 つの列が必要です (1 つは行頭用、もう 1 つは行末用)。そのため

parallelplot(~df[,c("npvi","rpvi")] | PatientGroup,data=df)

動作するはずであり、生成します

ここに画像の説明を入力

サンプルデータが与えられました。(出力から、少なくとも 2 つの変数が必要な理由が明確になることを願っています。)

于 2014-09-10T05:23:40.460 に答える