(搜索路径?)晶格中的奇点::parallelplot
我需要构建一个平行坐标图,我正在尝试使用(搜索路径?)晶格中的奇点::parallelplot,r,plot,lattice,parallel-coordinates,R,Plot,Lattice,Parallel Coordinates,我需要构建一个平行坐标图,我正在尝试使用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", "M
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
有一个非常奇怪的公式语法。它实际上需要一个矩阵/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")
应该工作,它产生
给定样本数据。(希望从输出中可以清楚地看出为什么至少需要两个变量。)如果使用
df$npvi
是否有效?或者可能是~npvi
,类似于帮助页面上的示例?完美!非常感谢。是的,数据是dplyr过程的结果,因此还需要将其转换为普通的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")
parallelplot(~df[,c("npvi","rpvi")] | PatientGroup,data=df)