[R] plotting

Greg Snow Greg.Snow at intermountainmail.org
Fri Aug 31 21:11:38 CEST 2007


Here is the approach that I would take.

Use a different plot for each day but line them all up like so:

x <- c(1, 2, 10, 12)
y <- c(100, -20, 50, 25)
day <- c(1,1,2,2)

my.df <- data.frame(x=x,y=y,day=day)

par(mfrow=c(1,2), oma=c(5,4,4,2)+0.1, mar=c(0,0,0,0))

tmp.yr <- range(my.df$y)

for (i in 1:2){
  with(subset(my.df, day==i), 
	plot(x,y,type='l', xlab='', ylab='', axes=FALSE, ylim=tmp.yr)
  )
  axis(1, outer=TRUE)
  if(i==1) axis(2, outer=TRUE)
  box()
  mtext( paste('Day',i), 1, line=3 )
}

You will probably want to play with the xlims so that there is the
appropriate amount of space between plots and so that each day
represents the same scale (in this example day 1 shows 1 hour spread and
day 2 shows 2 hours, probably want to keep that the same).

You could also replace the box() line with one final box('inner') after
the loop if you don't want the line(s) between days.

Hope this helps,


-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111
 
 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of yoooooo
> Sent: Friday, August 31, 2007 12:31 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] plotting
> 
> 
> Hi, let's say I have data
> 
> x = c(1, 2, 10, 12)
> y = c(100, -20, 50, 25)
> 
> if I go plot(x, y), then the default x-axis range goes from 1 
> to 12. Is there a way to change it so that the axis looks like:
> 
> ----|-----|-----|-----|----
>      1       2       10     12
> 
> This doesn't seem reasonable but let's say I want to plot 
> intraday graph with axis.POSIXct, my data is only from 8:30 
> to 4 every day and I have these data for days.. i don't want 
> to see a straight line every night.. Is there a way I can do this? 
> 
> Thanks!!!
> -yoooooooooooooooooo
> 
> 
> 
> 
> 
> 
> --
> View this message in context: 
> http://www.nabble.com/plotting-tf4361709.html#a12431743
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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