Dear All, I am trying to produce log-log plots in R and I was wondering if any of you have a 'template' for generating these with 'nice' labels and log-log grids? I know I can set up axes individually and use the intervals I want, however, I will be producing a large number of these plots and would not like to do this manually for each of them + I am very new to R and at the moment do not have much time that I could spend figuring this out by myself..... Any help would be greatly appreciated! Thanks Tibi ____________________________________________________ Alexandru Tiberiu CODILEAN PhD Candidate Departmental IT Committee PG Rep. Department of Geographical and Earth Sciences East Quadrangle, Room 309 University Avenue University of Glasgow Glasgow G12 8QQ UK Tel: +44 (0) 141 330 4872 ext. 0935 Fax: +44 (0) 141 330 4894 Email: tcodilean at ges.gla.ac.uk Home: http://web.ges.gla.ac.uk/~tcodilean/ GRASS Mirror: http://pc188.geog.gla.ac.uk/grass/ A gleekzorp without a tornpee is like a quop without a fertsneet (sort of)
Hi plot(1:100,1:100, log="xy") abline(v=seq(0,100,10), lty=3) abline(h=seq(0,100,10), lty=3) or plot(1:100,1:100, log="xy", axes=F) axis(1, at=(seq(0,100,20))) axis(2, at=(seq(0,100,10))) abline(v=seq(0,100,20), lty=3) abline(h=seq(0,100,10), lty=3) isn't it nice? See some other magigraphical parameters in ?par HTH Petr BTW I do not have much time to spent it on such a task either especially when only you know what you want to achieve. On 9 Feb 2006 at 17:02, Alexandru Codilean wrote: From: "Alexandru Codilean" <tcodilean at geog.gla.ac.uk> To: r-help at stat.math.ethz.ch Date sent: Thu, 09 Feb 2006 17:02:28 +0000 Subject: [R] nice log-log plots Send reply to: tcodilean at ges.gla.ac.uk <mailto:r-help-request at stat.math.ethz.ch?subject=unsubscribe> <mailto:r-help-request at stat.math.ethz.ch?subject=subscribe>> Dear All, > > I am trying to produce log-log plots in R and I was wondering if any > of you have a 'template' for generating these with 'nice' labels and > log-log grids? > > I know I can set up axes individually and use the intervals I want, > however, I will be producing a large number of these plots and would > not like to do this manually for each of them + I am very new to R and > at the moment do not have much time that I could spend figuring this > out by myself..... > > Any help would be greatly appreciated! > Thanks > Tibi > ____________________________________________________ > > Alexandru Tiberiu CODILEAN > PhD Candidate > Departmental IT Committee PG Rep. > > Department of Geographical and Earth Sciences > East Quadrangle, Room 309 > University Avenue > University of Glasgow > Glasgow G12 8QQ UK > > Tel: +44 (0) 141 330 4872 ext. 0935 > Fax: +44 (0) 141 330 4894 > Email: tcodilean at ges.gla.ac.uk > > Home: http://web.ges.gla.ac.uk/~tcodilean/ > GRASS Mirror: http://pc188.geog.gla.ac.uk/grass/ > > A gleekzorp without a tornpee is like a quop without a fertsneet (sort > of) > > ______________________________________________ > 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.htmlPetr Pikal petr.pikal at precheza.cz
Here's what I do, I'm open to any suggestions and improvements... seq.log=function(x1,x2="1"){ if(length(x1)==2){x2=x1[2];x1=x1[1];} n1=floor(log(x1)/log(10)) n2=floor(log(x2)/log(10)) suff=NULL; if(x1==1000){n1=n1+1;} if(x2==1000){suff=1000;} if(n2-(log(x2)/log(10))==0){ n2=n2-1; suff=x2; } dn=n2-n1+1 return(c(as.vector( t(10^(log(matrix(1:9,dn,9,byrow=T) )/log(10)+matrix(n1:n2,dn,9) ))),suff)) } nextint=function(v){ w=numeric(length(v)) for(i in 1:length(v)){ if(v[i]<0){ w[i]=floor(v[i]); }else{ w[i]=ceiling(v[i]); } } return(w) } range.log=function(X){ return(10^nextint(log(range(X,na.rm=T))/log(10))) } range.decade=function(X){ return(nextint(log(range(X,na.rm=T))/log(10))) } plot.loglog=function(X,Y,majorgrid=T,minorgrid=T,ygrid=Y,xlim=range(X),ylim=range(Y),...){ ### Work on axis, ticks and labels rX=range(xlim,na.rm=T) rY=range(ylim,na.rm=T) #minor grid xmgrid=seq.log(rX) ymgrid=seq.log(rY) #Major grid px=nextint(log(rX)/log(10)) Vpx=px[1]:px[2]; xMgrid=10^(Vpx) py=nextint(log(rY)/log(10)) Vpy=py[1]:py[2]; yMgrid=10^(Vpy) xlim=range(xMgrid); ylim=range(yMgrid); ### Plotting plot.empty(rX,rY,log="xy",xlim=xlim,ylim=ylim,...) # grid if(minorgrid){ abline(v=xmgrid,col="lightgray") abline(h=ymgrid,col="lightgray") } if(majorgrid){ abline(v=xMgrid,col="gray") abline(h=yMgrid,col="gray") } par(new=T) # plot plot(X,Y,log="xy",axes=F,frame.plot=T,ylim=ylim,xlim=xlim,...) #labels #par(las=1) #horizontal for(px in pretty(Vpx)){ axis(1,at=10^px,bquote(10^.(px))) } for(py in pretty(Vpy)){ axis(2,at=10^py,bquote(10^.(py))) } } #plot.loglog(f,S,type="o",col=4,pch="",xaxs="i",yaxs="i"); -- View this message in context: http://n4.nabble.com/nice-log-log-plots-tp793534p1592527.html Sent from the R help mailing list archive at Nabble.com.