I have two types of data to create two types of plot, bar and line. They have different y axis, but same x axis. They are each categorized by the same category levels
Example Code:
data <- data.frame( Station = sample(LETTERS[seq( from = 1, to = 4 )],50, rep = TRUE),
Date = sample(seq(as.Date('2015/01/01'), as.Date('2015/12/31'), by="day"), 50),
Presence = sample(0:10,50,rep = TRUE),
Noise = sample(70:130,50, rep=TRUE))
noise <- ggplot()+
geom_line(data = data,aes(x=Date, y= Noise, color= Station))+
scale_x_date(date_breaks = "1 month")+
facet_wrap(~Station, ncol=2, strip.position="right")+
theme(axis.title.x = element_text(margin = margin(t = 20)))+
guides(colour = guide_legend(override.aes = list(size=3)))+
coord_cartesian(xlim = c(as.Date("2015-02-01"),as.Date("2015-10-30")))+
labs( x='Date')+
theme_classic(base_family = "serif")
pres <-ggplot()+
geom_bar(data = data,aes(x= Date, y = Presence), stat = "identity")+
scale_x_date(date_breaks = "1 month")+
facet_wrap(~Station, ncol=2, strip.position="right")+
theme(axis.title.x = element_text(margin = margin(t = 20)))+
coord_cartesian(xlim = c(as.Date("2015-02-01"),as.Date("2015-10-30")))+
labs( x='Date')+
theme_classic(base_family = "serif")
What I would like to do, is to combine the two plots, but label with the same facet (Station).
Quick example I made in photoshop would look something like this:
etc.
Any help would be appreciated!
Read more here: Source link