0

Ok, [R3.4.2 + ggplot2] Using the data example listed below, how do I add a second data plot? I tried this example which I found on this site;

library(ggplot2]
** This is part of the origanl code ****
rpt<-read.csv(file="rpt.csv,header=T)
rpt1<-read.csv(file="rpt1.csv,header=T)
*** code starts here *****
ggplot(rpt,aes(JulianDate,w)) + geom_line(aes(color="First   line")) +
             geom_line(data=rpt1, aes(color="Second line")) + labs(color="Legend text")

The first plot has x=rpt$JulianDate, y=rpt1$w; and the second plot has x1= rpt1$JDAy and y2=rpt1$wolf)

The data (use dget(_) to read it):

structure(list(
JDay = c(57023, 57024, 57027, 57028, 57029, 57031, 57032, 57035, 57037),
Obs = c(1, 1, 1, 1, 1, 1, 1, 1, 1),
w = c(71, 105, 64, 44, 45, 38, 66, 49, 28),
WStd = c(0, 0, 0, 0, 0, 0, 0, 0, 0),
wolf = c(91.59, 135.45, 82.56, 56.76, 58.05, 49.02, 85.14, 63.21, 36.12),
Adj = c(0, 0, 0, 0, 0, 0, 0, 0, 0)),
.Names = c("JDay", "Obs", "w", "WStd", "wolf", "Adj"),
class = "data.frame",
row.names =  c(NA, -9L))
peak
  • 105,803
  • 17
  • 152
  • 177
David Jackson
  • 53
  • 3
  • 9
  • 1
    Please share the data (`rpt` and `rpt1`) via `dput()`, see [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – Eric Fail Jan 23 '16 at 03:22
  • 2
    There is no R 3.4.2 and will not be for another 2 years. I think you need (at the very least) to name the columns in the second aes. – IRTFM Jan 23 '16 at 03:25
  • Eric, Sorry I don't know what you mean by "dput()"? rpt and rpt1 contain the exact same data.. – David Jackson Jan 23 '16 at 03:31
  • Eric, I 've edited the original post to included the output from dput() – David Jackson Jan 23 '16 at 03:53
  • Thanks for sharing some of your data. Is the `structure` you shared `rpt` or `rpt1`? Please share both. – Eric Fail Jan 23 '16 at 14:51

1 Answers1

3

In your comment, you say that rpt and rpt1 have the same data. Therefore, I think this is what you are asking for

library(ggplot2)
ggplot(rpt, aes(x=JDay)) + 
  geom_line(aes(y=w, color="First   line")) +
  geom_line(aes(y=wolf, color="Second line")) + 
  labs(color="Legend text")

enter image description here

Liesel
  • 2,929
  • 2
  • 12
  • 18
  • @DavidJackson thanks, no problem - it'd be great if you could accept the answer http://stackoverflow.com/help/accepted-answer – Liesel Jan 24 '16 at 05:09
  • I do have one other question? How can Increase the number of Julian Dates(JDay) displayed along the Y axis? Factor? – David Jackson Jan 24 '16 at 05:15
  • @DavidJackson use `scale_x_continuous` and `breaks` see http://stackoverflow.com/questions/11335836/increase-number-of-axis-ticks-in-ggplot2 – Liesel Jan 24 '16 at 06:24