我具有類似於這兩個數據幀:在一個情節結合geom_point和geom_line
date <- c("2014-07-06", "2014-07-06","2014-07-06","2014-07-07", "2014-07-07","2014-07-07","2014-07-08","2014-07-08","2014-07-08")
TIME <- c("01:01:01", "10:02:02", "18:03:03","01:01:01", "10:02:02", "18:03:03","01:01:01", "10:02:02", "18:03:03")
depth <- c(12, 23, 4, 15, 22, 34, 22, 12, 5)
temp <- c(14, 10, 16, 13, 10, 9, 10, 14, 16)
depth.temp <- data.frame(date, TIME, depth, temp)
depth.temp$asDate<-as.Date(depth.temp$date)
date <- c("2014-07-06", "2014-07-07","2014-07-08")
meandepth <- c(13, 16, 9)
cv <- c(25, 9, 20)
depth.cv <- data.frame(date, meandepth, cv)
depth.cv$asDate<-as.Date(depth.cv$date)
從第一個我已經創建以下情節:
library(ggplot2)
p1 <- qplot(asDate, depth, data=depth.temp, colour=temp, size = I(5), alpha = I(0.3))+ scale_y_reverse()
p1 + scale_colour_gradientn(colours = rev(rainbow(12)))
而從第二個該曲線:
p2 <- ggplot(depth.cv, aes(x=asDate, y=meandepth))+ scale_y_reverse()
p2 + geom_line(aes(size = cv))
我想將兩個圖合併成一個,在後面的點和前面的行中,任何含義stions?請注意,點和線不是從相同的數據而是從兩個不同的數據幀中派生出來的。
可能重複的[如何將2個圖(ggplot)合併爲一個圖?](http://stackoverflow.com/questions/21192002/how-to-combine-2-plots-ggplot-into-one-plot) – figurine
它是相似的但是在這個問題中,點和線都是從同一個數據框中創建的,而我使用兩個單獨的數據框作爲點和線 –
將代碼排列成與鏈接答案類似的結構,並確保定義哪個數據框用於每個情節,它會正常工作。 – figurine