Bagaimana cara melapisi satu plot di atas plot lainnya di ggplot2 seperti yang dijelaskan dalam kalimat berikut? Saya ingin menggambar deret waktu abu-abu di atas deret waktu merah menggunakan ggplot2 di R (sekarang deret waktu merah berada di atas deret waktu abu-abu dan saya ingin grafik saya terbalik). Ini kode saya (saya membuat beberapa data untuk menunjukkan masalah saya, kumpulan data sebenarnya jauh lebih kompleks):
install.packages("ggplot2")
library(ggplot2)
time <- rep(1:100,2)
timeseries <- c(rep(0.5,100),rep(c(0,1),50))
upper <- c(rep(0.7,100),rep(0,100))
lower <- c(rep(0.3,100),rep(0,100))
legend <- c(rep("red should be under",100),rep("grey should be above",100))
dataset <- data.frame(timeseries,upper,lower,time,legend)
ggplot(dataset, aes(x=time, y=timeseries)) +
geom_line(aes(colour=legend, size=legend)) +
geom_ribbon(aes(ymax=upper, ymin=lower, fill=legend), alpha = 0.2) +
scale_colour_manual(limits=c("grey should be above","red should be under"),values = c("grey50","red")) +
scale_fill_manual(values = c(NA, "red")) +
scale_size_manual(values=c(0.5, 1.5)) +
theme(legend.position="top", legend.direction="horizontal",legend.title = element_blank())
alpha
di garis geom Anda - person rawr   schedule 27.04.2014geom_line
Anda di akhir sehingga lapisan garis abu-abu adalah yang terakhir digambar dan karenanya tepat di atas. - person Ramnath   schedule 27.04.2014