0

I have 4 graphs that are similar to this one (just use a different dataframe (don, don1, don2). I want to combine them in one graph with the line colors designated as the dataframe with a common legend.

 ggplot(don, aes(x=poscum, y=pval)) +

 # Show all points
 geom_line() +
 # custom X axis:
 scale_x_continuous( label = axisdf$CHR, breaks= axisdf$center ) +
 scale_y_continuous(expand = c(0, 0) ) +     # remove space between plot area 
  and x axis

 # Custom the theme:
 theme_bw() +
 theme( 
   legend.position="none",
   panel.border = element_blank(),
   panel.grid.major = element_line(colour="white"),
   panel.grid.minor = element_line(colour="white"),
   axis.ticks = element_line(colour = "black"),
   axis.line = element_line(colour = "black"),
 )
aosmith
  • 34,856
  • 9
  • 84
  • 118
user1977802
  • 313
  • 6
  • 10
  • 18
  • 1
    Please provide [example data](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) in order to make your issue reproducible! – jay.sf Jul 03 '18 at 13:59
  • 1
    There are many options for this. Answers to [this question](https://stackoverflow.com/questions/13649473/add-a-common-legend-for-combined-ggplots) cover most of them. – aosmith Jul 03 '18 at 14:01

1 Answers1

1

You can use facets for this. Like so:

donall <- data.frame(rbind(don, don1, don2), group= rep("don", nrow(don)), rep("don1", nrow(don1)), rep("don2", nrow(don2)))

ggplot(donall, aes(x=poscum, y=pval)) +
 geom_line()+
facet_wrap(~group, ncol=2) +....
Luke Hayden
  • 692
  • 4
  • 8