R 将具有相同y轴和不同x轴的图合并

R 将具有相同y轴和不同x轴的图合并,r,ggplot2,tidyverse,R,Ggplot2,Tidyverse,我正在研究债券市场在七天的窗口期内对某些事件的反应 因此,我想创建一个图表,绘制出日期前后的债券收益率反应。我的数据如下 df <- Date APP DE10 2014-09-22 0 1.010 2014-09-19 0 1.043 2014-09-18 0 1.081 2014-09-17 0 1.050 2014-09-16 0 1.061 2014-09-15

我正在研究债券市场在七天的窗口期内对某些事件的反应

因此,我想创建一个图表,绘制出日期前后的债券收益率反应。我的数据如下

df <- Date       APP  DE10 
      2014-09-22 0    1.010 
      2014-09-19 0    1.043
      2014-09-18 0    1.081
      2014-09-17 0    1.050
      2014-09-16 0    1.061
      2014-09-15 0    1.067
      2014-09-12 1    1.082
      2014-09-11 0    1.041
      2014-09-10 0    1.047
      2014-09-09 0    0.996
      2014-09-08 0    0.953
      2014-09-05 0    0.928
      2014-09-04 1    0.970
      2014-09-03 0    0.955
      2014-09-02 0    0.931
      2014-09-01 0    0.882

df除了@MichaelChirico建议的之外,这里还有一个解决方案

require(tidyverse)

Bond10$Date您是如何从
df
Bond10
数据帧的?将x轴重新定义为某个日期之前/之后的几天
DE10 <- ggplot(Bond10) + 
   geom_line(aes(x=Date, y=DE10)) +
   labs(title="Germany", x="", y="Bond yield") +
   scale_x_date(limits = as.Date(c('2017-10-23','2017-10-30')), 
   expand=c(0.1,0))+
   geom_vline(aes(xintercept=as.Date("2017-10-26"), color="Event"))+
   scale_y_continuous(limits = c(0.3, 0.6), expand = c(0.1,0)) +  
   theme(legend.position='none',
       axis.text.x=element_blank(),axis.ticks.x=element_blank(), 
       plot.margin=unit(c(0.2,0.2,0,0.2), "cm"))
require(tidyverse)
Bond10$Date <- ymd(Bond10$Date) #needed to do this because the dates were imported as characters 

Bond10 <- Bond10 %>% mutate(APP_date = ifelse(APP == 1, Date, NA))

ggplot(Bond10) + 
  geom_line(aes(x=Date, y=DE10)) +
  geom_vline(aes(xintercept= APP_date , color="Event"))

#I removed the redundant bits and pieces, especially your totally wrong x-limits