# r-plot

7 messages
Open this post in threaded view
|

## 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
|

## 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
|

## Re: r-plot

Open this post in threaded view
|

## 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
|

## 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)