ggplot:生成彩色段的图

时间:2013-12-19 09:24:40

标签: r ggplot2

我有bands,一个包含一组行的(日期,y)坐标的数据框。 线看起来几乎是完美的水平线。

                          entryL      entryH         exitL        exitH
11/06/2013 00:00:00 -0.011269079 0.011269079 -0.0005634540 0.0005634540
11/05/2013 00:00:00 -0.011247277 0.011247277 -0.0005623638 0.0005623638
11/04/2013 00:00:00 -0.011246974 0.011246974 -0.0005623487 0.0005623487
11/01/2013 00:00:00 -0.011239644 0.011239644 -0.0005619822 0.0005619822
10/31/2013 00:00:00 -0.011237719 0.011237719 -0.0005618859 0.0005618859
10/30/2013 00:00:00 -0.011236857 0.011236857 -0.0005618428 0.0005618428
10/29/2013 00:00:00 -0.011278355 0.011278355 -0.0005639178 0.0005639178

我有posFrame,一个包含另一行(Spread)和标记列(Positioning)的数据框,用于定义系统的状态。

                    Positioning        Spread
11/06/2013 00:00:00        Idle -1.309504e-03
11/05/2013 00:00:00        Idle  2.517881e-03
11/04/2013 00:00:00        Idle  1.035712e-03
11/01/2013 00:00:00        Idle  6.470740e-03
10/31/2013 00:00:00        Idle  4.975187e-03
10/30/2013 00:00:00        Idle  3.655266e-03
10/29/2013 00:00:00        Idle -8.704032e-03
10/28/2013 00:00:00       Short  2.790278e-03
10/25/2013 00:00:00       Short  6.690602e-03
10/24/2013 00:00:00       Short  3.098176e-03

我想将两个数据框一起绘制。这是我目前的尝试。

bands$time <- rownames(bands)
bands$time <- as.POSIXct(bands$time, format = "%m/%d/%Y %H:%M:%S") 
posFrame$time <- rownames(posFrame)
posFrame$time <- as.POSIXct(posFrame$time, format = "%m/%d/%Y %H:%M:%S")        
frame.m <- melt(frame, id = "time")
ggplot() +          
  geom_line(data = frame.m, aes (x = time, y = value, colour= variable)) +
  geom_jitter(data = posFrame, aes(x = time, y = Spread, colour = Positioning)) +
  geom_line(data = posFrame, aes(x = time, y = Spread)) +
  guides(color=guide_legend(override.aes=list(shape=c(NA,16),linetype=c(1,0))))

enter image description here

图片看起来不太好看。 如果我可以在颜色与前一个标记钻石的颜色匹配的彩色线段中绘制Spread线,那就太棒了。

此外,我不明白为什么图例混合了与Positioning相关的钻石颜色和与乐队相关的实线颜色。

我不知道如何继续...... 谢谢。

0 个答案:

没有答案
相关问题