จะวางซ้อนพล็อตหนึ่งไว้ด้านบนของอีกอันใน ggplot2 ตามที่อธิบายไว้ในประโยคต่อไปนี้ได้อย่างไร ฉันต้องการวาดอนุกรมเวลาสีเทาที่ด้านบนของอนุกรมเวลาสีแดงโดยใช้ ggplot2 ใน R (ตอนนี้อนุกรมเวลาสีแดงอยู่เหนืออนุกรมเวลาสีเทา และฉันต้องการให้กราฟของฉันเป็นอย่างอื่น) นี่คือรหัสของฉัน (ฉันสร้างข้อมูลบางส่วนเพื่อแสดงปัญหาของฉัน ชุดข้อมูลจริงซับซ้อนกว่ามาก):
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
ในเส้น geom ของคุณ - person rawr   schedule 27.04.2014geom_line
ของคุณที่ส่วนท้ายเพื่อให้เลเยอร์เส้นสีเทาเป็นเลเยอร์สุดท้ายและอยู่ด้านบนสุด - person Ramnath   schedule 27.04.2014