Hi all, I'm attempting to make a quite-specific plot where the axes cross at the origin and with gridlines for guidance. I've been using ablines to create the reference lines because I want a lot of control as to where they are placed on the axis. This command works very well for such control. However... These ablines don't seem to work when I specify the origin as 0,0. They go beyond the x-axis at both ends, rendering a quite ugly graph (and they push back the y-axis title some). Behold: ### x<-c(0,1,2,3,4,5) y<-c(0,2,4,6,8,10) plot(x,y, axes=FALSE) axis(1,at=c(0,1,2,2.5,3,4,5),pos=0) axis(2,at=c(0,2,4,6,8,10),pos=0) abline(h=c(1,2,3,4,5)) ### Is there any way for me to specify that these ablines should not go beyond the y-axis extent? I just want a pretty graph! Thanks! Ryan -- Ryan Utz, Ph.D. Aquatic Ecologist/STREON Scientist National Ecological Observatory Network Home/Cell: (724) 272-7769 Work: (720) 746-4844 ext. 2488 [[alternative HTML version deleted]]
On Tue, 2011-05-03 at 10:36 -0600, Ryan Utz wrote:> Hi all, > > I'm attempting to make a quite-specific plot where the axes cross at the > origin and with gridlines for guidance. I've been using ablines to create > the reference lines because I want a lot of control as to where they are > placed on the axis. This command works very well for such control. > However... > > These ablines don't seem to work when I specify the origin as 0,0. They go > beyond the x-axis at both ends, rendering a quite ugly graph (and they push > back the y-axis title some). > > Behold: > > ### > x<-c(0,1,2,3,4,5) > y<-c(0,2,4,6,8,10) > > plot(x,y, axes=FALSE) > axis(1,at=c(0,1,2,2.5,3,4,5),pos=0) > axis(2,at=c(0,2,4,6,8,10),pos=0) > abline(h=c(1,2,3,4,5)) > ### > > Is there any way for me to specify that these ablines should not go beyond > the y-axis extent? I just want a pretty graph! > > Thanks! > Ryan >Maybe you could use lines()? plot(1:2) lines(c(1,2),c(1.5,1.5))
Check your par() settings, specifically "xpd". For more control see ?clip. If that does not do enough for you then use lines or segments for complete control. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Ryan Utz > Sent: Tuesday, May 03, 2011 10:36 AM > To: r-help at r-project.org > Subject: [R] Controlling the extent of ablines on plot > > Hi all, > > I'm attempting to make a quite-specific plot where the axes cross at > the > origin and with gridlines for guidance. I've been using ablines to > create > the reference lines because I want a lot of control as to where they > are > placed on the axis. This command works very well for such control. > However... > > These ablines don't seem to work when I specify the origin as 0,0. They > go > beyond the x-axis at both ends, rendering a quite ugly graph (and they > push > back the y-axis title some). > > Behold: > > ### > x<-c(0,1,2,3,4,5) > y<-c(0,2,4,6,8,10) > > plot(x,y, axes=FALSE) > axis(1,at=c(0,1,2,2.5,3,4,5),pos=0) > axis(2,at=c(0,2,4,6,8,10),pos=0) > abline(h=c(1,2,3,4,5)) > ### > > Is there any way for me to specify that these ablines should not go > beyond > the y-axis extent? I just want a pretty graph! > > Thanks! > Ryan > > -- > > Ryan Utz, Ph.D. > Aquatic Ecologist/STREON Scientist > National Ecological Observatory Network > > Home/Cell: (724) 272-7769 > Work: (720) 746-4844 ext. 2488 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.
Apparently Analagous Threads
- Linking 2 columns in 2 databases and applying a function
- Finding/identifying a value within a factor
- Boxplot of multiple vectors with different lengths
- Please delete my e-mail judit.barroso@montana.edu
- Counting number of rows with two criteria in dataframe