1

我有一个看起来像这样的 R 脚本:

library(ggplot2)

df <- read.table("path/to/file.txt", header=TRUE)

df$seq <- 1:nrow(df)

p1 <- qplot(x=ref_PA,y=RMSD,data=df) + geom_line()
print(p1)

然后我绘制如下所示的数据:

在此处输入图像描述

问题是这些点是通过它们出现在 x 轴上的顺序连接的,有没有办法通过seq我在我的数据框中生成的列来连接这些点(df

我的数据框示例如下所示:

> head(df)
  ref_pdb next_pdb   RMSD ref_PA next_PA delta_PA seq
1    1qiv     1lin 0.5879   1337    1388       51   1
2    1lin     1a29 0.3970   1388    1362       26   2
3    1a29     3ewt 1.1926   1362    1380       18   3
4    3ewt     3ewv 1.2140   1380    1412       32   4
5    3ewv    3gof2 1.6565   1412    1418        6   5
6   3gof2    3gof1 0.3080   1418    1419        1   6

我知道你们都喜欢可重现的例子,所以这是我的数据框,seq列:

structure(list(ref_pdb = structure(c(13L, 8L, 1L, 42L, 43L, 45L, 
44L, 15L, 14L, 20L, 16L, 17L, 18L, 10L, 9L, 30L, 28L, 21L, 23L, 
22L, 33L, 46L, 49L, 4L, 32L, 40L, 24L, 25L, 38L, 7L, 31L, 29L, 
27L, 26L, 39L, 6L, 19L, 11L, 47L, 48L, 41L, 2L, 36L, 37L, 50L, 
3L, 12L, 5L, 34L, 35L, 51L, 52L), .Label = c("1a29", "1cll", 
"1clm", "1cm1", "1exr", "1ggz", "1iq5", "1lin", "1mxe1", "1mxe2", 
"1ooj", "1osa", "1qiv", "1qiw1", "1qiw2", "1qs71", "1qs72", "1qtx", 
"1rfj", "1vrk", "1wrz", "1yr5", "1zuz", "2f3y", "2f3z", "2ix71", 
"2ix72", "2k0j", "2k61", "2l7l", "2lgf", "2o5g", "2o60", "2r281", 
"2r282", "2v01", "2v02", "2vay", "2ygg", "3bxl", "3cln", "3ewt", 
"3ewv", "3gof1", "3gof2", "3gp2", "3sjq1", "3sjq2", "3sui", "4cln", 
"4g27", "4g28"), class = "factor"), next_pdb = structure(c(9L, 
1L, 42L, 43L, 45L, 44L, 15L, 14L, 20L, 16L, 17L, 18L, 11L, 10L, 
30L, 28L, 21L, 23L, 22L, 33L, 46L, 49L, 4L, 32L, 40L, 24L, 25L, 
38L, 8L, 31L, 29L, 27L, 26L, 39L, 7L, 19L, 12L, 47L, 48L, 41L, 
2L, 36L, 37L, 50L, 3L, 13L, 5L, 34L, 35L, 51L, 52L, 6L), .Label = c("1a29", 
"1cll", "1clm", "1cm1", "1exr", "1g4y", "1ggz", "1iq5", "1lin", 
"1mxe1", "1mxe2", "1ooj", "1osa", "1qiw1", "1qiw2", "1qs71", 
"1qs72", "1qtx", "1rfj", "1vrk", "1wrz", "1yr5", "1zuz", "2f3y", 
"2f3z", "2ix71", "2ix72", "2k0j", "2k61", "2l7l", "2lgf", "2o5g", 
"2o60", "2r281", "2r282", "2v01", "2v02", "2vay", "2ygg", "3bxl", 
"3cln", "3ewt", "3ewv", "3gof1", "3gof2", "3gp2", "3sjq1", "3sjq2", 
"3sui", "4cln", "4g27", "4g28"), class = "factor"), RMSD = c(0.5879, 
0.397, 1.1926, 1.214, 1.6565, 0.308, 1.736, 1.2785, 1.8785, 0.8899, 
0.7611, 1.7691, 1.9543, 0.3456, 1.6468, 1.9575, 1.2693, 0.6397, 
0.8545, 2.1215, 2.0911, 1.4976, 2.312, 2.3692, 2.6759, 2.0306, 
0.4719, 0.7809, 1.6036, 2.2123, 3.8186, 9.2451, 2.4978, 14.0809, 
2.1417, 2.1248, 1.6743, 1.2079, 0.2223, 1.2878, 0.2746, 0.5786, 
0.5356, 0.6444, 0.7692, 0.3618, 0.4772, 2.1024, 1.1866, 22.9332, 
0.2094, 0.8705), ref_PA = c(1337, 1388, 1362, 1380, 1412, 1418, 
1419, 1384, 1425, 1493, 1423, 1426, 1508, 1436, 1438, 1476, 1484, 
1512, 1466, 1504, 1507, 1456, 1441, 1413, 1510, 1432, 1499, 1463, 
1432, 1465, 1475, 1469, 1499, 1486, 1647, 1635, 1634, 1571, 1637, 
1638, 1623, 1627, 1596, 1602, 1641, 1631, 1677, 1652, 1577, 1603, 
1649, 1645), next_PA = c(1388, 1362, 1380, 1412, 1418, 1419, 
1384, 1425, 1493, 1423, 1426, 1508, 1436, 1438, 1476, 1484, 1512, 
1466, 1504, 1507, 1456, 1441, 1413, 1510, 1432, 1499, 1463, 1432, 
1465, 1475, 1469, 1499, 1486, 1647, 1635, 1634, 1571, 1637, 1638, 
1623, 1627, 1596, 1602, 1641, 1631, 1677, 1652, 1577, 1603, 1649, 
1645, 1653), delta_PA = c(51, 26, 18, 32, 6, 1, 35, 41, 68, 70, 
3, 82, 72, 2, 38, 8, 28, 46, 38, 3, 51, 15, 28, 97, 78, 67, 36, 
31, 33, 10, 6, 30, 13, 161, 12, 1, 63, 66, 1, 15, 4, 31, 6, 39, 
10, 46, 25, 75, 26, 46, 4, 8), seq = 1:52), .Names = c("ref_pdb", 
"next_pdb", "RMSD", "ref_PA", "next_PA", "delta_PA", "seq"), row.names = c(NA, 
-52L), class = "data.frame")
4

2 回答 2

3

我认为您正在寻找geom_path而不是geom_line. 见?geom_path

p1 <- qplot(x=ref_PA,y=RMSD,data=df) + geom_path()
p1

在此处输入图像描述

于 2013-02-06T11:42:56.307 回答
1

除了@plannapus,连接的顺序基于行的顺序。例如随机化seq和重新排序行:

library(reshape)
df$seq = sample(df$seq)
df = sort_df(df, "seq")

现在顺序不同了:

qplot(x=ref_PA,y=RMSD,data=df) + geom_path()

在此处输入图像描述

于 2013-02-06T11:49:01.193 回答