我遇到ggplot
的问题。
我假装使用列名作为x variable
绘制此数据框,并且行具有必须为每个复制绘制的值。请注意,有两个大的组标识为TR
和UT
,我想要用红色和蓝色(或默认颜色)绘制颜色。
我知道ggplot
要求融化数据,所以我做了。但是当我使用融化数据时,我丢失了我希望通过x variable
为每个复制连接的各个值。
> 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)
我认为数据是正确绘制的,但我想连接各个点以查看它们在x
增加时的位置。后来我想为每个组添加一些平均值。
答案 0 :(得分:0)
如果您想要点和线,请考虑直接使用ggplot()
。此外,您在rownames()
中有重要的分组信息,这使得分组更加困难。在这里,我将rownames移动到数据本身,然后融化;这样可以确定哪些点应该落在同一行
ggplot(melt(cbind(pend2x45, id=rownames(pend2x45))),
aes(x=variable, y=value, color= grupo, group=id)) +
geom_point() + geom_line()
产生