[R] two plots on the same axis
baptiste auguie
baptiste.auguie at googlemail.com
Wed Oct 7 10:38:34 CEST 2009
Hi,
Your two data sets have a different year so I'm not sure what you want
to do with the x axis.
The code below plots both data sets on the same graph, with a range of
two years,
d1 <- read.table("~/Downloads/2005.txt")
d2 <- read.table("~/Downloads/2006.txt")
cleanup <- function(d){
names(d) <- c("year", "month", "day", "value")
transform(d, date=as.Date(paste("0", year, month, day, sep=""), "%y%m%d"))
}
d1 <- cleanup(d1)
d2 <- cleanup(d2)
d <- rbind(d1, d2)
d <- transform(d, year=factor(year))
with(d, plot(date,value))
# prettier with ggplot2
library(ggplot2)
qplot(date, value, data=d, colour=year)
HTH,
baptiste
2009/10/7 ogbos okike <ogbos.okike at gmail.com>:
> Good morning. I wish to plot two data on the same axis. I tried plot(x,y,
> type = "l") for the first and tried to use lines or points(x,y, lty = 2, col
> = 4) to add or plot the second data on alongside the first. However, what I
> got was not encouraging.
> I have attached the two data and would be pleased if anybody could be of
> help.
> Thank you
> Best regards
> Ogbos
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
More information about the R-help
mailing list