I'm not sure if you want to just align the two plots or actually combine them. Are either of these useful, or have I not got the right end of the stick?
Align
If you want to align them, I'd reccomend using patchwork:
plot_data = function(df){
df %>%
mutate(row = row_number()) %>%
pivot_longer(cols = -row, values_drop_na = TRUE) %>%
ggplot(aes(value)) + aes(row, value, color=name) +
geom_jitter()+ geom_hline(yintercept=1.4,linetype="dashed") + ylab("Log") + xlab("") +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black")) + scale_color_manual(values = "purple") +
theme(axis.ticks.x = element_blank(),axis.text.x = element_blank()) + theme(legend.title=element_blank()) +
ggtitle("") + theme(axis.title.x = element_text(size = 15)) +
theme(axis.title.y = element_text(size = 15)) +
annotate(geom = "rect", xmin = 60, xmax = 300,
ymin = -Inf, ymax = Inf,
color = "#D5D8DC",
fill = "#D5D8DC", alpha = 0.4
)
}
plt1 = plot_data(data1)
plt2 = plot_data(data2)
patchwork::wrap_plots(plt1, plt2, guides = "collect")
Combine
To plot both datasets on the same plot, I'd probably look to bind them together first, then color by some additional column that is used to distinguish between them:
bind_rows(
data1 %>% mutate(row = row_number()) %>% mutate(df = "A"),
data2 %>% mutate(row = row_number()) %>% mutate(df = "B")
) %>%
ggplot(aes(row, LOD, color = df)) +
geom_jitter()+ geom_hline(yintercept=1.4,linetype="dashed") + ylab("Log") + xlab("") +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black")) +
scale_color_manual(values = c("purple", "green")) +
theme(axis.ticks.x = element_blank(),axis.text.x = element_blank()) + theme(legend.title=element_blank()) +
ggtitle("") + theme(axis.title.x = element_text(size = 15)) +
theme(axis.title.y = element_text(size = 15)) +
annotate(geom = "rect", xmin = 60, xmax = 300,
ymin = -Inf, ymax = Inf,
color = "#D5D8DC",
fill = "#D5D8DC", alpha = 0.4)