0

r 我有一个这样的数据框:

dput(head(final,50))
structure(list(Date = structure(c(15779, 15780, 15781, 15782, 
15783, 15784, 15785, 15786, 15787, 15788, 15789, 15790, 15791, 
15792, 15793, 15794, 15795, 15796, 15797, 15798, 15799, 15800, 
15801, 15802, 15803, 15804, 15805, 15806, 15807, 15808, 15809, 
15810, 15811, 15812, 15813, 15814, 15815, 15816, 15817, 15818, 
15819, 15820, 15821, 15822, 15823, 15824, 15825, 15826, 15827, 
15828), class = "Date"), Pc = c(17.688, 10.824, 9.804, 11.136, 
13.272, 12.42, 12.84, 15.156, 10.848, 9, 19.188, 12.84, 14.628, 
16.104, 17.22, 10.716, 7.788, 16.488, 18.66, 14.904, 14.004, 
16.08, 10.668, 9.024, 12.912, 11.364, 11.988, 11.316, 14.1, 9.96, 
7.308, 13.044, 14.7, 12.636, 12.624, 15.696, 9.624, 8.124, 17.136, 
13.428, 12.984, 13.14, 15.012, 10.5, 8.1, 11.964, 13.308, 12.972, 
13.38, 14.556)), .Names = c("Date", "Pc"), row.names = c("1", 
"6", "11", "16", "21", "26", "31", "36", "41", "46", "51", "56", 
"61", "66", "71", "76", "81", "86", "91", "96", "101", "106", 
"111", "116", "121", "126", "131", "136", "141", "146", "151", 
"156", "161", "166", "171", "176", "181", "186", "191", "196", 
"201", "206", "211", "216", "221", "226", "231", "236", "241", 
"246"), class = "data.frame")

我需要创建一个 ggplot 我需要一些范围数据是不同的颜色。我试过这个:

ggplot() + geom_line(subset(final, Date < as.Date(c("2013-08-06"))), aes(Date, Pc, colour=blue, size=1)) + geom_line(subset(final, Date > as.Date(c("2013-08-05"))), aes(Date, Pc, colour=red, size=1.2))

我收到此错误:

Error: ggplot2 doesn't know how to deal with data of class uneval

可以在ggplot中做这样的事情吗?

4

2 回答 2

2

您需要将数据作为命名参数传递,geom_line(data=subset(...), ...)因为data它是第二个参数。你也可以反转你的aesand subsetingeom_line来完成同样的事情。

查看?geom_line更多信息。

于 2013-08-06T20:49:12.500 回答
0

问题可能是您没有将任何参数传递给ggplot()命令吗?尝试您列出的完全相同的命令,除了ggplot(data=final).

于 2013-08-07T13:55:55.197 回答