目标:绘制如下图像:
特点: 1.两个不同的时间序列; 2.下面板有一个反向y轴; 3.阴影超过两个地块.
可能的解决方案:
1.刻面不合适 - (1)不能只使一个刻面的y轴反转,同时保持其他刻面不变.(2)难以逐个调整各个方面.
2.使用视口使用以下代码排列单个图:
library(ggplot2)
library(grid)
library(gridExtra)
##Import data
df<- read.csv("D:\\R\\SF_Question.csv")
##Draw individual plots
#the lower panel
p1<- ggplot(df, aes(TIME1, VARIABLE1)) + geom_line() + scale_y_reverse() + labs(x="AGE") + scale_x_continuous(breaks = seq(1000,2000,200), limits = c(1000,2000))
#the upper panel
p2<- ggplot(df, aes(TIME2, V2)) + geom_line() + labs(x=NULL) + scale_x_continuous(breaks = seq(1000,2000,200), limits = c(1000,2000)) + theme(axis.text.x=element_blank())
##For the shadows
#shadow position
rects<- data.frame(x1=c(1100,1800),x2=c(1300,1850),y1=c(0,0),y2=c(100,100))
#make shadows clean (hide axis, ticks, labels, background and grids)
xquiet …
Run Code Online (Sandbox Code Playgroud) 我在R中有一个图,X轴上有日期/时间(POSIXct),Y轴有一些数据.
我希望在x轴上每个日期的下午3点到6点之间提供x轴上的阴影