While writing a function that includes placing grid lines at the same position as the axis ticks, I found that the axis* functions don't return anything. Thus I have had to copy the appropriate function, removing the call to axis() and adding a line to return the tick positions. Is there a more elegant way to determine the tick positions on an axis? Thanks. Jim (normally bitwrit at ozemail.com.au - my modem is toast)
Which plotting function are you using ? I think most of plotting can accept xaxt="n" which is the command to supress the x-axis. If this works, at least you do not have to redefine the function. Examples plot(1:10, xaxt="n") hist( rnorm(100), xaxt="n" ) boxplot( rnorm(10), rnorm(10), rnorm(10), xaxt="n" ) Reading help("par") will also shows you that xaxp might be useful but I have not managed to get this working. Maybe someone on the list can explain why the following does not work : plot(1:100, xaxp=c(x1=0,x2=100,n=20) ) par( xaxp=c(x1=0,x2=100,n=20) ); plot(1:100) Regards, Adai On Thu, 2005-02-24 at 10:08 +1100, fls wrote:> While writing a function that includes placing grid lines at the same position > as the axis ticks, I found that the axis* functions don't return anything. > Thus I have had to copy the appropriate function, removing the call to axis() > and adding a line to return the tick positions. Is there a more elegant way > to determine the tick positions on an axis? Thanks. > > Jim > > (normally bitwrit at ozemail.com.au - my modem is toast) > > ______________________________________________ > 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 >
?axis where you will find See Also: 'axTicks' returns the axis tick locations corresponding to 'at=NULL'; 'pretty' is more flexible for computing pretty tick coordinates and does _not_ depend on (nor adapt to) the coordinate system in use. Tom> -----Original Message----- > From: fls [mailto:fls at fls.org.au] > Sent: Thursday, 24 February 2005 7:08 AM > To: r-help at stat.math.ethz.ch > Subject: [R] Getting tick positions > > > While writing a function that includes placing grid lines at > the same position > as the axis ticks, I found that the axis* functions don't > return anything. > Thus I have had to copy the appropriate function, removing > the call to axis() > and adding a line to return the tick positions. Is there a > more elegant way > to determine the tick positions on an axis? Thanks. > > Jim > > (normally bitwrit at ozemail.com.au - my modem is toast) > > ______________________________________________ > 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 >
Jim Lemon wrote:> Thanks for the answers - I should have been more specific as I had already > tried axTicks and pretty. > > The function in question is gantt.chart() in the latest plotrix package > (Thanks to Scott Waichler for the original code). I settled on axis.POSIXct > as it seemed the most appropriate for this function, but couldn't find a way > to get the positions of the ticks so that I could then draw grid lines along > the months|days|hours. While the trick of copying the original function > works, I wondered why the axis* functions don't return the tick positions as > barplot returns the bar positions. Is there any reason not to return "z", or > is it just historical?I think historical. Replacing return R_NilValue; by return at; in do_axis (plot.c) should do the trick (well, I'm a bit afraid concerning the UNPROTECT, you might need to do that later, after the recording stuff?). Uwe Ligges> Jim > > ______________________________________________ > 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
Dear Group, I am calculating correlation coeff. between two populations. After calculating the cor.coefs I want to represent them as a matrix file. a b c d A 1 0 1 1 B 1 1 1 1 C 1 0 1 0 D 0 1 1 1 could any one please help me how can i acheive this:> dim(e1)[1] 22283 60> dim(e2)[1] 22283 158> sink("old_new.txt") >round(cor(cbind(e1,e2),use="complete.obs")) >sink()Currently this is the way my result looksL a A 1 B 1 C 1 D 0 b A 0 B 1 C 0 D 1 I want to see my result as: a b c d A 1 0 1 1 B 1 1 1 1 C 1 0 1 0 D 0 1 1 1 thankyou srini
What version of R under which operating system? I just tried something similar and got something sensible, as follows: set.seed(1) e1 <- array(1:6, dim=c(3,2), dimnames=list(NULL, LETTERS[1:2])) e2 <- array(rnorm(6), dim=c(3,2), dimnames=list(NULL, letters[1:2])) e12 <- cor(e1, e2) e12. <- round(e12) sink("e12.txt") e12. sink() ##################### File "e12.txt" contained the following: a b A 0 -1 B 0 -1 An alternative is the following: write.table(e12., "e12.csv", quote=FALSE) File "e12.csv" contained the same as *.txt. Are your names actually "A", "B", etc., or do they include long character strings? If the latter, that would explain what you got. If the former, what do you get from "options()$width"? I suspect it may be some small number. hope this helps. spencer graves p.s. Did you read the posting guide, "http://www.R-project.org/posting-guide.html"? If you had followed that more carefully, especially regarding supplying a real, simple example with a few lines that would illustrate your problem, you would have gotten a quicker answer. p.p.s. I found "options()$width" from "www.r-project.org" -> search -> "R site search" -> "output line width". It was in the sixth hit. Srinivas Iyyer wrote:>Dear Group, I am calculating correlation coeff. >between two populations. After calculating the >cor.coefs I want to represent them as a matrix file. > > a b c d >A 1 0 1 1 >B 1 1 1 1 >C 1 0 1 0 >D 0 1 1 1 > > >could any one please help me how can i acheive this: > > > >>dim(e1) >> >> >[1] 22283 60 > > >>dim(e2) >> >> >[1] 22283 158 > > >>sink("old_new.txt") >>round(cor(cbind(e1,e2),use="complete.obs")) >>sink() >> >> > >Currently this is the way my result looksL > a >A 1 >B 1 >C 1 >D 0 > b >A 0 >B 1 >C 0 >D 1 > > > > >I want to see my result as: > a b c d >A 1 0 1 1 >B 1 1 1 1 >C 1 0 1 0 >D 0 1 1 1 > > >thankyou >srini > >______________________________________________ >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 > >
Thanks for the answers - I should have been more specific as I had already tried axTicks and pretty. The function in question is gantt.chart() in the latest plotrix package (Thanks to Scott Waichler for the original code). I settled on axis.POSIXct as it seemed the most appropriate for this function, but couldn't find a way to get the positions of the ticks so that I could then draw grid lines along the months|days|hours. While the trick of copying the original function works, I wondered why the axis* functions don't return the tick positions as barplot returns the bar positions. Is there any reason not to return "z", or is it just historical? Jim