[R] bar and line plot
Felipe Carrillo
mazatlanmexico at yahoo.com
Sat Sep 27 20:07:47 CEST 2008
Hi Jim:
Thanks for your suggestion from the plotrix package. That's exactly what I was looking for, however, I can't see the dates along the X axis and neither the temp line (I only see the thicks). Is there a way to actually plot the temp line? I have been using the ggplot2 package and I am able to do a barplot for my NumEggs(max value is 14) but I can't plot the temp data because the scales are way different (the max value is around 55-60). I guess I could try to plot the temp separately and put the graphs side by side. Thanks Jim.
> From: Jim Lemon <jim at bitwrit.com.au>
> Subject: Re: [R] bar and line plot
> To: mazatlanmexico at yahoo.com
> Cc: r-help at stat.math.ethz.ch
> Date: Saturday, September 27, 2008, 4:48 AM
> Felipe Carrillo wrote:
> > Hello All:
> > Using the below dataset how can I make a barplot
> with
> > Date(X) and NumEggs(Y) by Site. Then plot
> Temp(lineplot)
> > It seems really simple, but I am having a hard
> time trying to
> > do it by Site. Thanks
> >
> Hi Felipe,
> This might do what you want:
>
> fdc<-read.table("fdc.dat",header=TRUE)
> fdc$Date<-as.Date(fdc$Date,format="%Y-%m-%d")
> library(plotrix)
> par(mar=c(5,4,4,4))
> barp(fdc$NumEggs,names.arg=fdc$Date,xlab="Date",ylab="Number
> of eggs",
> main="Number of eggs by date",col=fdc$Site)
> # a low trick to align the x-axis for the temperature line
> startDate<-as.Date("2008-04-21",format="%Y-%m-%d")
> lines(fdc$Date-startDate,fdc$Temp/5)
> axis(4,at=10:12,labels=c(50,55,60))
> mtext("Temperature",side=4,at=5,line=1)
> legend(2,14,levels(fdc$Site),fill=1:3)
>
> Jim
More information about the R-help
mailing list