2014-09-09 4 views
1

평행 좌표 플롯을 구성해야하는데이 경우 lattice::parallellplot을 사용하려고합니다. 지금, (검색 경로?) oddities in lattice :: parallelplot

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 기능은 데이터 프레임의 열을 찾을 수없는 올 있습니다 .. data.frame의 변수를 찾을 수있을 것 같지 않습니다? 세션에 대한

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" 
+0

'df $ npvi '를 사용하면 효과가 있습니까? –

+0

또는 '~ npvi', 도움말 페이지의 예와 비슷합니까? –

답변

1

, parallelplot는 매우 기괴한 수식 구문이 있습니다. 실제로 행렬/data.frame이 수식의 오른쪽으로 전달되어야합니다. 또한이 행렬에는 최소한 두 개의 열이 있어야합니다. 평행 한 플롯의 선은이 값들 사이에 그려집니다.

하지만 먼저 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이 필요하고 최소한 두 개의 컬럼이 필요하다. (라인 시작과 라인 종료를 위해 하나씩) Therfore

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

작동해야하며 샘플 데이터 제공

enter image description here

생산하고 있습니다. (출력에서 왜 적어도 두 개의 변수가 필요한지 알기를 바랍니다.)

+0

완벽한! 고맙습니다! 예, 데이터는 dplyr 프로 시저의 결과이므로 일반 'data.frame'으로 변환해야합니다. –