# r-plot

7 messages
Open this post in threaded view
|
Report Content as Inappropriate

## r-plot

 Dear R-community I have a grueling problem which appears to be impossible to solve: I want to make a simple plot, here is my code: http://gist.github.com/118550Unfortunately, the annotation of both the x- and y-axis are not correct, as you can see in the following picture: I am not an expert of R, so maybe someone can point me to the solution of this problem, i.e. both of the axes should start and end at the min / max values of the two vectors. Thanks in advance!! Best, Durden
Open this post in threaded view
|
Report Content as Inappropriate

## Re: r-plot

 durden10 wrote: > Dear R-community > > I have a grueling problem which appears to be impossible to solve: > I want to make a simple plot, here is my code: http://gist.github.com/118550> Unfortunately, the annotation of both the x- and y-axis are not correct, as > you can see in the following picture: > http://www.nabble.com/file/p23739356/plot.png  > I am not an expert of R, so maybe someone can point me to the solution of > this problem, i.e. both of the axes should start and end at the min / max > values of the two vectors. > >   Hi Durden, This example seems to work for me. Is it just the X and Y axis labels that you want? data_corr<-data.frame(  Win=c(-0.08,-0.07,-0.01,-0.01,0.03,0.08,0.1,0.13,   0.18,0.19,0.195,0.2,0.28,0.3,0.4),  Calgary=c(11,7,5,4,3,8,6,7,3,2,1,8,0,1,3) ) par(tcl=0.35,xaxs="r") # Switch tick marks to insides of axes plot(data_corr, type = "p", xlab="VS signal change",  ylab="Depression scale",axes=FALSE, col = "blue", lwd = 2) #y-axis axis(2, tcl=0.35,at=0:11) #x-axis test2<-seq(0,0.4,by=0.1) axis(1, tcl=0.35,at=test2) box() abline(lm(data_corr[,2]~data_corr[,1])) Jim ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: r-plot

Open this post in threaded view
|
Report Content as Inappropriate

## Re: r-plot

 In reply to this post by durden10 > I want to make a simple plot, here is my code: http://gist.github.com/118550> Unfortunately, the annotation of both the x- and y-axis are not correct, as > you can see in the following picture: > http://www.nabble.com/file/p23739356/plot.png  > I am not an expert of R, so maybe someone can point me to the solution of > this problem, i.e. both of the axes should start and end at the min / max > values of the two vectors. >From the help page on par: 'xaxs' The style of axis interval calculation to be used for the           x-axis.  Possible values are '"r"', '"i"', '"e"', '"s"',           '"d"'.  The styles are generally controlled by the range of           data or 'xlim', if given. Style '"r"' (regular) first extends           the data range by 4 percent at each end and then finds an           axis with pretty labels that fits within the extended range.           Style '"i"' (internal) just finds an axis with pretty labels           that fits within the original data range. You've explicitly set xaxs="r", when you really want xaxs="i".  You can also explicitly set the axis limits using xlim/ylim parameters in the call to plot. Compare these examples: #Ex 1 plot(1:10)      #implicitly uses par(xaxs="r", yaxs="r") unless you've changed something #Ex 2 oldpar <- par(xaxs="i", yaxs="i") plot(1:10) par(oldpar) #Ex 3 plot(1:10, xlim=c(-5, 15), ylim=c(-100, 100)) Regards, Richie. Mathematical Sciences Unit HSL ------------------------------------------------------------------------ ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

## r-plot 2nd attempt

 In reply to this post by durden10 First of all, thanks a lot for your quick & helpful comments! I have come down to this: Win<- c(-0.005276404,  0.081894394, -0.073461539,  0.184371967,  0.133189670, -0.006239016,      -0.063616699,  0.196754234,  0.402148743,  0.104408425,           0.036910154,  0.195227863,  0.212743723,  0.280889666,  0.300277802) Calgary<- c(5,  8, 11,  3,  7,  4,  7,  1,  3,  6,  3,  2,  8,  0,  1) data_corr <- data.frame(Win,Calgary) plot(data_corr, type = "p", axes=FALSE,  col = "blue", lwd = 2) #y-axis axis(2, tcl=0.35,seq(1,11,by=2)) #x-axis axis(1, tcl=0.35,seq(-0.1,0.5,by=0.1)) box() abline(lm(data_corr[,2]~data_corr[,1])) It works for the y-axis, but unfortunately, the x-axis is still not working: It starts at 0 and end at 0.4, but it should start at -0.1, as mentioned in the code (cf picture)
Open this post in threaded view
|
Report Content as Inappropriate

## Re: r-plot 2nd attempt

 On Wed, 2009-05-27 at 06:06 -0700, durden10 wrote: > First of all, thanks a lot for your quick & helpful comments! > > I have come down to this: > > Win<- c(-0.005276404,  0.081894394, -0.073461539,  0.184371967, > 0.133189670, -0.006239016,      -0.063616699,  0.196754234,  0.402148743, > 0.104408425, >  0.036910154,  0.195227863,  0.212743723,  0.280889666,  0.300277802) > Calgary<- c(5,  8, 11,  3,  7,  4,  7,  1,  3,  6,  3,  2,  8,  0,  1) > > data_corr <- data.frame(Win,Calgary) > plot(data_corr, type = "p", axes=FALSE,  col = "blue", lwd = 2) > > #y-axis > axis(2, tcl=0.35,seq(1,11,by=2)) > > #x-axis > axis(1, tcl=0.35,seq(-0.1,0.5,by=0.1)) > box() > > abline(lm(data_corr[,2]~data_corr[,1])) > > It works for the y-axis, but unfortunately, the x-axis is still not working: > It starts at 0 and end at 0.4, but it should start at -0.1 Why? Your data extend to ~-0.07. > , as mentioned in > the code (cf picture) :confused: > http://www.nabble.com/file/p23742121/Rplots_2.png  You didn't adjust the x-axis limits to tell R that you wanted -0.1 to be include on the lower end of the axis. R isn't clairvoyant you know! I've tidied your script and altered it to extend the x-axis a bit so that -0.1 is included: Win <- c(-0.005276404,  0.081894394, -0.073461539, 0.184371967,          0.133189670, -0.006239016, -0.063616699, 0.196754234,            0.402148743, 0.104408425, 0.036910154, 0.195227863,          0.212743723, 0.280889666, 0.300277802) Calgary<- c(5,  8, 11,  3,  7,  4,  7,  1,  3,  6,  3,  2,  8,  0,  1) data_corr <- data.frame(Win, Calgary) plot(Calgary ~ Win, data = data_corr, type = "p", axes = FALSE,        col = "blue", lwd = 2, xlim = c(-0.1,0.5)) ##                          ^^^^^^^^^^^^^^^^^^ axis(2, tcl = 0.35, seq(1, 11, by=2)) axis(1, tcl = 0.35, seq(-0.1, 0.5, by=0.1)) box() abline(lm(Calgary ~ Win, data = data_corr)) HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%  Dr. Gavin Simpson             [t] +44 (0)20 7679 0522  ECRC, UCL Geography,          [f] +44 (0)20 7679 0565  Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk  Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.