I have moderate size data with ~75K data points. I am trying to plot a facet_wrapped line graph with ggplot using multiple variables in the data. The code is like this:
library(ggplot2)
library(ggthemes)
df <- read.delim("D-CL-allblock.txt")
My_Theme = theme(
title = element_text(size = 20, face = "bold"),
axis.title.x = element_text(size = 16, face = "bold"),
axis.text.x = element_text(size = 14),
axis.title.y = element_text(size = 16, face = "bold"),
axis.text.y = element_text(size = 14),
legend.text = element_text(size = 14),
aspect.ratio = 0.8,
legend.position = "right",
panel.background = element_rect(fill = "white", colour = "grey50"),
axis.line = element_line(size = 3, colour = "grey80"),
axis.text = element_text(size = 10),
axis.ticks.length.y = unit(.25, "cm"),
axis.ticks.length.x = unit(.25, "cm"))
plot <- ggplot(data = df, aes(Pos, value, group = Stock)) +
geom_line(aes(color = Stock), size = 1) +
facet_grid(variable ~ Chr, scales = 'free') + ###############use scales = "free" for individual axes length
scale_color_brewer(palette="Reds") + #put palette="Paired" for blues
# scale_color_brewer(palette="Paired") +
My_Theme +
theme_clean()
plot
Head of the data looks like
Chr Pos variable value Stock
1 2L 1 d1 -0.488857515 Control
2 2L 2 d1 0.295529037 Control
3 2L 3 d1 0.003036192 Control
4 2L 4 d1 -1.113652386 Control
5 2L 5 d1 -0.668819366 Control
6 2L 6 d1 -1.302787150 Control
Stock variables are - Control and Late, Chr variables are - 2L, 2R, 3L, 3R, and X, variable values are d1, d2, d3, d4.
ggplot is unable to plot this, takes a long time and then gives an unreadable plot which doesn't make sense.
Any help regarding what I am doing wrong?