剪切function_ggplot

时间:2016-01-11 14:44:12

标签: r algorithm

我想要一张成本与时间的关系图。但是当我运行下面的代码时,有时我得到以下错误,并且y不包括(0到1e + 06)(1e + 06,2e + 06)(2e + 06,3e + 06)。如何修改以下代码。

Error in seq.default(from = best$lmin, to = best$lmax, by = best$lstep) :'from' must be of length 1, cut, R

df <- structure(list(ID = structure(c(1L, 2L, 2L, 3L, 3L, 4L, 4L, 4L, 
      4L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 5L, 6L), .Label = c("R1", "R2", 
      "R3", "R4", "R5", "R6"), class = "factor"), cost = c(123000L, 120000L, 
      2000000L, 2500000L, 2500000L,2500000L, 2500000L, 2600000L, 2505000L, 2530000L, 2500000L, 1500000L, 
      2500003L, 2503300L, 2500005L, 
      3000000L, 2000000L, 500000L), Time = c(123L, -12L, NA, -15L, NA, 17L, 18L, 
     -9L, 88L, 666L, 7L, 78L, 188L, 111L, 121L, 141L, 189L, 161L), 
      number = c(14L, 12L, 15L, 17L, NA, 17L, 22L, 95L, NA, 67L, 
      7L, 8L, 7L, 118L, NA, 140L, 180L, 1611L)), .Names = c("ID", 
      "cost", "Time", "number"), row.names = c(NA, -18L), class = "data.frame")

df$Colour <- cut(df$cost, breaks = c(0,1000000,2000000,3000000), 
                           labels = c("0<=<1000000", "1000000<=<2000000","2000000<=<3000000"), 
                           right = TRUE)
p <- ggplot(df, aes(Time,cost, colour = Colour)) 
p <- p + geom_point() + xlab("Time") + ylab("cost")
p<-p + facet_grid(Colour~., scales = "free")
#p

0 个答案:

没有答案