[R] Same y-axis on multiple plots?

Andreas Bergstrøm andreas.bergstrom at hiof.no
Mon Jan 25 15:52:13 CET 2010


Greetings,

I am attempting to use R throug PL/R in PostgreSQL to make several graphs (they show usage over time for radiochannels).

However, as some never go above 100 in a 24 hour period, and others go well over 500, they get different y-axis values (which normally would be a good thing). However, as I want to overlay the graphs to add/remove channels in CSS on a webpage, I need a set y-axis.

I have looked through the documentation, google and the mailinglist as ylim, setting xpd=F and modifying clip, plot.window, but I can't seem to find what I am looking for. I am certain that it is something simple, and would be gratefull if someone could point me in the right direction.


R code run through PL/R in Postgres is as follows:

mymain <- "Graph 3";
myxlab <- "Time: 24/Hours";
myylab <- "Number of Hits";

png(''/tmp/graph3.png'');
plot(str,type="b",main=mymain,xlab=myxlab,ylab=myylab,lwd=2, axes=F, ylim.max=0);
clip(0, 25, 0, 600);
axis(1, at = c(0, 3, 6, 9, 12, 15, 18, 21, 24));
axis(2, at = c(0, 100, 200, 300, 400, 500, 600));
abline(h = c(100, 200, 300, 400, 500, 600), lty=2);
mtext("Usage over a  24 hour period",side=3);
dev.off();



Contents of str structure:
str <-
structure(list(timeofday = 1:23, connections = c(116L, 87L, 51L, 
44L, 75L, 147L, 264L, 275L, 233L, 294L, 132L, 140L, 198L, 171L, 
248L, 226L, 257L, 246L, 210L, 189L, 180L, 238L, 303L)), .Names = c("timeofday", 
"connections"), row.names = c("1", "2", "3", "4", "5", "6", "7", 
"8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", 
"19", "20", "21", "22", "23"), class = "data.frame")

Regards,

--
Andreas Bergstrøm
Østfold University College
Dept. of Computer Sciences
Tel: +47 69 21 53 71
http://media.hiof.no/



More information about the R-help mailing list