0

I have a five plots which contain 4 lines (two of them are below):

g1<-ggplot(df)+geom_line (aes(x=Time, y=z1, color="a"))+geom_line (aes(x=Time, y=z6, color="b"))+
  geom_line (aes(x=Time, y=z11, color="c"))+geom_line (aes(x=Time, y=z16, color="d"))+
  scale_color_discrete(name="")+labs(title="")

g2<-ggplot(container)+geom_line (aes(x=Time, y=z2, color="a"))+geom_line (aes(x=Time, y=z7, color="b"))+
  geom_line (aes(x=Time, y=z12, color="c"))+geom_line (aes(x=Time, y=z17, color="d"))+
  scale_color_discrete(name="")+labs(title="")

Now I want to order it in a column with common x axis and separate y axes. Just like in the post. However, I can not find the solution.

Dmitry Senkovich
  • 5,521
  • 8
  • 37
  • 74
Nikola
  • 25
  • 4
  • Combine your datasets, use a single `ggplot` call, then facet. Your example is not reproducible. – Axeman Jul 28 '17 at 12:58
  • Thanks Axeman, that means it is possible to make a set of multi line graphs by calling only one ggplot? – Nikola Jul 28 '17 at 13:17
  • Yes. See [this](https://stackoverflow.com/questions/3777174/plotting-two-variables-as-lines-using-ggplot2-on-the-same-graph) and [this](https://stackoverflow.com/questions/3099219/plot-with-2-y-axes-one-y-axis-on-the-left-and-another-y-axis-on-the-right). – Axeman Jul 28 '17 at 13:26
  • Still need your help. This is the data frame -> – Nikola Jul 29 '17 at 08:51
  • Time<-seq(as.Date('2016-01-01'),as.Date('2016-12-31'),by = "months") z<-data.frame(Time, replicate(20,sample(0:100,12,rep=TRUE))) g1<-ggplot(z)+geom_line (aes(x=Time, y=x1, color="O"))+geom_line (aes(x=Time, y=x6, color="S"))+ geom_line (aes(x=Time, y=x11, color="A"))+geom_line (aes(x=Time, y=x16, color="AR"))+ scale_color_discrete(name="")+labs(title="To")+ ylab("Flow") theme(legend.position='bottom', plot.margin=unit(c(1,2,0.5,0.5),'cm')) – Nikola Jul 29 '17 at 09:22
  • g2<-ggplot(z)+geom_line (aes(x=Time, y=x2, color="O"))+geom_line (aes(x=Time, y=x7, color="S"))+ geom_line (aes(x=Time, y=x12, color="G"))+geom_line (aes(x=Time, y=x17, color="AR"))+ scale_color_discrete(name="")+labs(title="Tr")+ ylab("Flow") g3<-ggplot(z)+geom_line (aes(x=Time, y=x3, color="O"))+geom_line (aes(x=Time, y=x8, color="S"))+ geom_line (aes(x=Time, y=z13, color="G"))+geom_line (aes(x=Time, y=x18, color="AR"))+ scale_color_discrete(name="")+labs(title="Lo") – Nikola Jul 29 '17 at 09:25
  • g4<-ggplot(z)+geom_line (aes(x=Time, y=x4, color="O"))+geom_line (aes(x=Time, y=x9, color="S"))+ geom_line (aes(x=Time, y=x14, color="G"))+geom_line (aes(x=Time, y=x19, color="AR"))+ scale_color_discrete(name="")+labs(title="Un") g5<-ggplot(z)+geom_line (aes(x=Time, y=z5, color="O"))+geom_line (aes(x=Time, y=x10, color="S"))+ geom_line (aes(x=Time, y=x15, color="G"))+geom_line (aes(x=Time, y=x20, color="AR"))+ scale_color_discrete(name="")+labs(title="EM") – Nikola Jul 29 '17 at 09:26
  • Now, I just need a multiplot of g1,g2,g3,g4 and g5 with a single legend and changeable widths and colours of lines. Thank you!! – Nikola Jul 29 '17 at 09:27

0 Answers0