library(ggplot2)
library(cowplot)
library(gggenomes)
data1 <- data.frame(
Window = as.factor(seq(0,3800, by = 100)),
Para1 = runif(39, min = 40, max = 50))
data2 <- data.frame(
Window = as.factor(seq(0,7400, by = 100)),
Para2 = runif(75, min = 40, max = 50))
p1 <- ggplot(data1, aes(x = as.factor(Window), y = Para1, group = 1)) +
geom_line(color = "grey") +
geom_ribbon(aes(ymin = 0, ymax = Para1), fill = "grey", alpha = 1) +
scale_x_discrete(expand = c(0.01,0.01),
breaks = c(0, 3800) # Show only first and last
) +
scale_y_continuous(
expand = c(0, 0),
limits = c(0, 101),
breaks = seq(0, 100, by = 50)
) +
theme_classic() +
theme(
panel.background = element_rect(fill = "transparent", color = NA),
plot.background = element_rect(fill = "transparent", color = NA),
) +
labs(x = "")
p1
p2 <- ggplot(data2, aes(x = as.factor(Window), y = Para2, group = 1)) +
geom_line(color = "grey") +
geom_ribbon(aes(ymin = 0, ymax = Para2), fill = "grey", alpha = 1) +
scale_x_discrete(expand = c(0.01,0.01),
breaks = c(0,7400) # Show only first and last
) +
scale_y_continuous(
expand = c(0, 0),
limits = c(0, 101),
breaks = seq(0, 100, by = 50)
) +
theme_classic() +
theme(
panel.background = element_rect(fill = "transparent", color = NA),
plot.background = element_rect(fill = "transparent", color = NA),
) +
labs(x = "")
p2
df <- data.frame(
seq_id = c("a", "b"),
length = c(3800,7400)
)
p3 <- gggenomes(seqs=df) +
geom_seq() +
scale_x_continuous(expand = c(0.01,0.01), breaks = seq(0, max(df$length)+100 , by = 1000)) +
scale_y_continuous(expand = c(0,0.4)) +
theme_classic()
narrow <- plot_grid(p1,
NULL, nrow = 1, rel_widths = c(0.5, 0.42))
plot_grid(narrow, p3, p2,
ncol = 1)
I am using
plot_grid()to combine three plots. but after applyingplot_grid(), it seems like it change theexpand()inscale_x_discrete().