Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 从数据框ggplot打印链接行数据_R_Plot_Ggplot2 - Fatal编程技术网

R 从数据框ggplot打印链接行数据

R 从数据框ggplot打印链接行数据,r,plot,ggplot2,R,Plot,Ggplot2,我在使用ggplot时遇到问题 我假装使用列名作为x变量来绘制这个数据帧,并且这些行具有必须为每个复制绘制的值。请注意,有两个大组标识为TR和UT,我希望以红色和蓝色(或默认颜色)绘制它们。 我知道,ggplot要求融化数据,所以我这样做了。但是当我使用熔化的数据时,我丢失了我想要通过x变量为每个复制连接的单个值 > dput(pend2x45) structure(list(grupo = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,

我在使用
ggplot
时遇到问题

我假装使用列名作为
x变量来绘制这个数据帧,并且这些行具有必须为每个复制绘制的值。请注意,有两个大组标识为
TR
UT
,我希望以红色和蓝色(或默认颜色)绘制它们。 我知道,
ggplot
要求融化数据,所以我这样做了。但是当我使用熔化的数据时,我丢失了我想要通过
x变量
为每个复制连接的单个值

> dput(pend2x45)
structure(list(grupo = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("TR", 
"UT"), class = "factor"), tra1 = c(0.753387533875337, 1, 0.983904465213214, 
1, 0.2701754385965, 0.49181478016852, 1, 0.313598519888998, 1, 
NA, 0.397802197802199, 0, 0.0242857142857152, 0, 0, 0, 0.420454545454549, 
0, 0, 0.251256281407036), tra2 = c(1, 0.931318681318686, 0.882658359294182, 
0.723856209150329, 0.589473684210547, 0.95112254443432, 0.637602179836513, 
0.985568917668843, 0.502304147465442, NA, 0.112087912087914, 
0, 0, 0, 1, 0, 0.520454545454553, 0, 0, 1), tra3 = c(0.1318879855465, 
0.865384615384395, 1, 0.308823529411692, 0, 0.43872778297471, 
0.193460490463153, 0.0599444958371586, 0.0230414746543652, NA, 
0, 0, 0, 0, 0, 0, 0, 0.111553784860556, 0, 0), tra4 = c(0.079494128274612, 
0.909340659340445, 0.786085150571166, 0.666666666666513, 0, 1, 
0.114441416893713, 0.696392229417014, 0.0645161290322338, NA, 
0, 0.334196891191631, 0, 0, 0, 0, 0, 0.231075697211109, 0, 0), 
    test1 = c(0.304426377597101, 0.421828171828164, 0.48078920041552, 
    0.52450980392156, 1, 0.228484565014087, 0.53950953678472, 
    0.455134135060122, 0.0552995391705048, NA, 1, 0.81088082901553, 
    1, 0.610756123535665, 0.666666666666647, 0.687817258883237, 
    0.102272727272727, 1, 0.992609016999254, 0.130653266331654
    ), test2 = c(0.499548328816612, 0.159840159840158, 0.923156801661775, 
    0.0604575163398688, 0.961403508771952, 0.32787652011234, 
    0.610354223433229, 1, 0, NA, 0.47912087912088, 1, 0.395714285714293, 
    1, 0.190476190476187, 1, 1, 0.274900398406379, 1, 0.135678391959796
    )), .Names = c("grupo", "tra1", "tra2", "tra3", "tra4", "test1", 
"test2"), row.names = c("TR2x45", "TR2x45.1", "TR2x45.1.1", "TR2x45.1.2", 
"TR2x45.1.3", "TR2x45.2", "TR2x45.3", "TR2x45.4", "TR2x45.5", 
"TR2x45.6", "UT2x45", "UT2x45.1", "UT2x45.1.1", "UT2x45.1.2", 
"UT2x45.1.3", "UT2x45.2", "UT2x45.3", "UT2x45.4", "UT2x45.5", 
"UT2x45.6"), class = "data.frame")
我最接近目标的是使用

mlt<-melt(pend2x45)
qplot(mlt,x=mlt$variable,y=mlt$value,col=mlt$grupo)

<代码> MLT

如果你想要点和线,那么直接考虑使用<代码> GPPLOTTH()/<代码>。另外,在

rownames()
中有重要的分组信息,这使得分组更加困难。在这里,我将行名移动到数据本身中,然后融化;这允许识别哪些点应落在同一条线上

ggplot(melt(cbind(pend2x45, id=rownames(pend2x45))), 
    aes(x=variable, y=value, color= grupo, group=id)) + 
    geom_point() + geom_line()
产生