[R] two plots on the same axis

2009-10-07 Thread ogbos okike
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
05  1  1  3974.8
05  1  2  3967.2
05  1  3  3817.7
05  1  4  3789.4
05  1  5  3803.6
05  1  6  3831.4
05  1  7  3878.6
05  1  8  3861.5
05  1  9  3850.4
05  1 10  3855.0
05  1 11  3900.9
05  1 12  3952.2
05  1 13  3954.7
05  1 14  3942.9
05  1 15  3955.0
05  1 16  3934.1
05  1 17  3859.2
05  1 18  3530.9
05  1 19  3299.9
05  1 20  3398.1
05  1 21  3305.5
05  1 22  3457.7
05  1 23  3753.8
05  1 24  3846.8
05  1 25  3896.9
05  1 26  3914.3
05  1 27  3917.9
05  1 28  3910.1
05  1 29  3938.0
05  1 30  3975.7
05  1 31  3945.0
05  2  1  3952.3
05  2  2  3948.1
05  2  3  3946.7
05  2  4  3957.1
05  2  5  3968.9
05  2  6  3990.2
05  2  7  3980.0
05  2  8  3965.8
05  2  9  3952.8
05  2 10  3942.0
05  2 11  3938.9
05  2 12  3967.6
05  2 13  3986.9
05  2 14  3992.8
05  2 15  3982.8
05  2 16  3986.3
05  2 17  3972.5
05  2 18  3951.4
05  2 19  3929.4
05  2 20  3928.5
05  2 21  3939.6
05  2 22  3951.5
05  2 23  3950.2
05  2 24  3956.3
05  2 25  3970.4
05  2 26  3981.4
05  2 27  3994.2
05  2 28  3988.9
05  3  1  3997.1
05  3  2  4003.9
05  3  3  4011.0
05  3  4  4017.0
05  3  5  4003.2
05  3  6  3993.1
05  3  7  3996.8
05  3  8  3999.1
05  3  9  3988.6
05  3 10  4002.2
05  3 11  3997.9
05  3 12  3981.5
05  3 13  3996.8
05  3 14  4026.5
05  3 15  4025.5
05  3 16  4021.8
05  3 17  4016.5
05  3 18  4011.7
05  3 19  3975.9
05  3 20  3981.0
05  3 21  3961.2
05  3 22  3965.2
05  3 23  3981.5
05  3 24  3996.4
05  3 25  3981.9
05  3 26  3979.0
05  3 27  3976.5
05  3 28  3973.7
05  3 29  3959.5
05  3 30  3974.0
05  3 31  3980.2
05  4  1  3972.3
05  4  2  3982.2
05  4  3  4008.9
05  4  4  4007.0
05  4  5  4009.1
05  4  6  3990.5
05  4  7  4002.5
05  4  8  4027.3
05  4  9  4047.8
05  4 10  4039.4
05  4 11  4025.0
05  4 12  4025.3
05  4 13  4006.2
05  4 14  4013.0
05  4 15  4018.7
05  4 16  4031.2
05  4 17  4037.3
05  4 18  4053.2
05  4 19  4065.3
05  4 20  4065.5
05  4 21  4042.3
05  4 22  4004.8
05  4 23  3974.9
05  4 24  3995.5
05  4 25  4007.9
05  4 26  4005.5
05  4 27  4019.7
05  4 28  4030.3
05  4 29  4045.4
05  4 30  4031.4
05  5  1  3995.6
05  5  2  3978.2
05  5  3  3993.3
05  5  4  4018.4
05  5  5  4027.6
05  5  6  4006.0
05  5  7  3985.5
05  5  8  3993.1
05  5  9  3817.5
05  5 10  3849.4
05  5 11  3880.4
05  5 12  3896.8
05  5 13  3911.0
05  5 14  3922.4
05  5 15  3703.7
05  5 16  3703.8
05  5 17  3783.5
05  5 18  3809.5
05  5 19  3805.4
05  5 20  3837.9
05  5 21  3876.8
05  5 22  3898.2
05  5 23  3925.6
05  5 24  3954.2
05  5 25  3980.9
05  5 26  4007.8
05  5 27  4033.5
05  5 28  4035.3
05  5 29  3957.9
05  5 30  3948.2
05  5 31  3958.8
05  6  1  3973.1
05  6  2  3984.0
05  6  3  4010.9
05  6  4  4027.2
05  6  5  4040.0
05  6  6  4049.8
05  6  7  4027.3
05  6  8  4023.0
05  6  9  4033.8
05  6 10  4051.4
05  6 11  4063.6
05  6 12  4023.0
05  6 13  3998.4
05  6 14  3996.8
05  6 15  3962.9
05  6 16  3922.2
05  6 17  3919.3
05  6 18  3953.7
05  6 19  3994.4
05  6 20  4004.1
05  6 21  3999.8
05  6 22  3981.9
05  6 23  4058.7
05  6 24  4030.6
05  6 25  3999.0
05  6 26  4012.5
05  6 27  4034.3
05  6 28  4044.1
05  6 29  4042.9
05  6 30  4050.3
05  7  1  4049.5
05  7  2  4042.0
05  7  3  4055.2
05  7  4  4059.7
05  7  5  4075.2
05  7  6  4087.6
05  7  7  4083.7
05  7  8  4071.0
05  7  9  4098.5
05  7 10  4024.6
05  7 11  3967.0
05  7 12  3957.2
05  7 13  3896.8
05  7 14  3913.0
05  7 15  3928.0
05  7 16  3888.0
05  7 17  3684.0
05  7 18  3713.6
05  7 19  3820.1
05  7 20  3915.7
05  7 21  4011.0
05  7 22  4004.8
05  7 23  4003.7
05  7 24  3993.1
05  8  2  3927.9
05  8  3  3916.7
05  8  4  3950.6
05  8  5  3936.2
05  8  6  3900.1
05  8  7  3814.6
05  8  8  3861.2
05  8  9  3913.0
05  8 10  3925.0
05  8 11  3907.4
05  8 12  3943.5
05  8 13  3934.6
05  8 14  3938.9
05  8 15  3952.2
05  8 16  3956.1
05  8 17  3976.6
05  8 18  3998.5
05  8 19  4009.5
05  8 20  4007.0
05  8 21  3994.8
05  8 22  4009.2
05  8 23  4042.2
05  8 24  3942.1
05  8 25  3842.2
05  8 26  3907.3
05  8 27  3954.9
05  8 28  3967.2
05  8 29  4014.9
05  8 30  4013.2
05  8 31  3999.4
05  9  1  4007.0
05  9  2  3988.5
05  9  3  3947.2
05  9  4  3946.2
05  9  5  3945.7
05  9  6  3956.0
05  9  7  3980.1
05  9  8  4003.5
05  9  9  3975.5
05  9 10  3903.8
05  9 11  3544.0
05  9 12  3509.6
05  9 13  3463.4
05  9 14  3533.4
05  9 15  3523.9
05  9 16  3567.0
05  9 17  3657.8
05  9 18  3763.7
05  9 19  3805.4
05  9 20  3848.3
05  9 21  3874.8
05  9 22  3901.1
05  9 23  3911.2
05  9 24  3946.8
05  9 25  3927.6
05  9 26  3938.6
05  9 27  3960.8
05  9 28  3961.2
05  9 29  3981.9
05  9 30  3991.5
05 10  1  3987.1
05 10  2  4003.5
05 10  3  4026.8
05 10  4  4044.3
05 10  5  4050.2
05 10  6  4062.4
05 10  7  4069.4
05 10  8  4049.9

Re: [R] two plots on the same axis

2009-10-07 Thread baptiste auguie
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.ok...@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@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.



__
R-help@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.


Re: [R] two plots on the same axis

2009-10-07 Thread Jim Lemon

On 10/07/2009 07:12 PM, ogbos okike wrote:

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.

Hi Ogbos,
Try this:

plot(oo1$daymon,oo1[,4],
 main=Two years of something,type=l,col=blue,
 ylim=c(3300,4400))
 lines(oo2$daymon,oo2[,4],col=red)
legend(oo1$daymon[100],3600,c(2005,2006),
 col=c(4,2),lty=1)

Jim

__
R-help@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.