[R] How do I ensure that the minimum value is always displayed on a y-axis in a plot?

John Kane jrkrideau at yahoo.ca
Mon Sep 14 16:38:48 CEST 2009


Try this:

Assuming your vector is x:

ylimits<-c(min(x)- .05,max(x)+ .05)                   
plot(x,type="l",yaxt="n",ann=FALSE,ylim=ylimits)  

By the way, if you are going to supply much data, it is better practice to use dput() .  Try dput(x) to see what I mean.   

--- On Mon, 9/14/09, Jorgy Porgee <jorgy.porgee at gmail.com> wrote:

> From: Jorgy Porgee <jorgy.porgee at gmail.com>
> Subject: [R] How do I ensure that the minimum value is always displayed on a y-axis in a plot?
> To: r-help at r-project.org
> Received: Monday, September 14, 2009, 9:42 AM
> Good day all,
> 
> I'm trying to plot a figure and ensure that the minimum and
> maximum
> values are always displayed. However, the code below does
> not display
> the minimum value, no matter what I try. Could someone
> please help?
> 
> Thanking you in advance,
> 
> George.
> 
> Code below for reproduction (apologies if the paste is too
> long)
> >blah
>   [1] 0.41955516 0.37330949 0.37934005 0.38013805
> 0.40092939 0.41809771
>   [7] 0.35506315 0.37619029 0.38832550 0.39542780
> 0.41286773 0.44871474
>  [13] 0.44615066 0.43361945 0.38145897 0.40604155
> 0.42088808 0.33563820
>  [19] 0.19898388 0.05405320 0.07195498 0.06063927
> 0.10984199 0.20232684
>  [25] 0.15127455 0.22510366 0.21140916 0.07260068
> 0.05777458 0.08828844
>  [31] 0.04021164 0.24469011 0.34492270 0.39574032
> 0.42518585 0.42548034
>  [37] 0.37197967 0.48975481 0.50734214 0.55670726
> 0.41196281 0.33531371
>  [43] 0.47829721 0.47731551 0.43365112 0.47014039
> 0.50725827 0.46507313
>  [49] 0.32546031 0.38638210 0.47445182 0.43344709
> 0.47184664 0.48753637
>  [55] 0.55147869 0.62923899 0.63642112 0.66178114
> 0.59527015 0.59549785
>  [61] 0.62225348 0.60587771 0.60169650 0.63869644
> 0.61497011 0.65405717
>  [67] 0.69497307 0.62576041 0.62001612 0.60824744
> 0.58845512 0.59354563
>  [73] 0.58475209 0.55517098 0.52625245 0.52072084
> 0.55999513 0.56649198
>  [79] 0.57620648 0.57745032 0.59226162 0.58934124
> 0.54486513 0.51508236
>  [85] 0.74226171 0.58931068 0.51018640 0.49098902
> 0.45596347 0.43259728
>  [91] 0.45967729 0.26489904 0.25191748 0.19439178
> 0.17408443 0.20808856
>  [97] 0.22975459 0.22893210 0.25564566 0.31440300
> 0.53385458 0.49516475
> [103] 0.49393954 0.51413002 0.51550473 0.49094308
> 0.54652848 0.52330680
> [109] 0.66077700 0.67473377 0.73252064 0.60095084
> 0.68951870 0.67420846
> [115] 0.69349983 0.67653648 0.67111012 0.73809505
> 0.70304421 0.50431098
> [121] 0.51570562 0.57064245 0.57074739 0.63965621
> 0.63229142 0.65723570
> [127] 0.64391499 0.82621738 0.85068029 0.89709948
> 0.91123501 0.88550389
> [133] 0.76118258 0.77473892 0.77503572 0.73966148
> 0.57395492 0.53487577
> [139] 0.54431602 0.57154920 0.57202015 0.60106360
> 0.57827979 0.61068995
> [145] 0.55431071 0.60882601 0.63072667 0.70043628
> 0.63970493 0.64275926
> [151] 0.58062481 0.56941537 0.52262351 0.53100501
> 0.55272148 0.80326824
> [157] 0.78036595 0.80721362 0.79298279 0.75516757
> 0.75579061 0.67656367
> [163] 0.70496972 0.68608556 0.66523708 0.72524320
> 0.72008161 0.71944444
> [169] 0.66725266 0.75883243 0.74635191 0.54621226
> 0.65989640 0.77764740
> [175] 0.65814792 1.00083188 1.02165546 0.94522872
> 0.90831836 0.88110308
> [181] 0.89816588 0.89028173 0.94347223 0.98161240
> 0.98384939 0.94526478
> [187] 0.97281886 0.98157746 0.96008129 0.96922374
> 0.97786087 0.99163911
> [193] 0.99454825 0.97736352 0.99095124 0.92813285
> 0.93952818 0.98855307
> [199] 0.98751104 1.00542472 1.00545473 1.02263743
> 1.01393869 1.03487649
> [205] 1.04497946 1.02959214 0.98269728 1.01594502
> 1.02254283 1.00999491
> [211] 1.03421722 0.82068414 0.78290122 0.82552434
> 0.77812239 0.73814563
> [217] 0.73692711 0.71827498 0.66419647 0.57225762
> 0.52777201 0.59094474
> [223] 0.63180748 0.60971980 0.61568132 0.59885033
> 0.58130928 0.54992662
> [229] 0.53327994 0.52765513 0.53013986 0.60648203
> 0.62806366 0.56185943
> [235] 0.57269468 0.54619305 0.53997574 0.49932167
> 0.52099655 0.57367695
> [241] 0.55302045 0.55270828 0.59010362 0.59723936
> 0.58141465 0.57682344
> [247] 0.58535031 0.58344239 0.59194913 0.59982716
> 0.66758340 0.72833184
> [253] 0.72775151 0.79754621 0.81961383 0.89888747
> 0.86068598 0.84862423
> [259] 0.84324231 0.86120500 0.77773796 0.79363973
> 0.79360194 0.80167689
> [265] 0.82430504 0.79068694 0.74700339 0.76740598
> 0.82838452 0.85449833
> [271] 0.80523549 0.86915548 0.91917996 1.00838100
> 1.01711474 0.88572847
> [277] 0.91220859 0.88790637 0.83414216 0.85770156
> 0.87551614 0.90779409
> [283] 0.95448958 0.97048682 0.95669389 1.07568609
> 1.02615707 1.21670864
> [289] 1.26424976 1.03758636 1.00911849 0.88467871
> 0.90480334 0.91616568
> [295] 0.81912570 0.80111286 0.47223969 0.64554445
> 0.64264599 0.60489611
> [301] 0.56542526 0.49117982 0.45614010 0.46773733
> 0.40172436 0.40196829
> [307] 0.43754909 0.36359256
> 
> ylimits<-range(c(blah,1.3))
> plot(blah,type="l",yaxt="n",ann=FALSE,ylim=ylimits)
> b<-ylimits[1]
> e<-ylimits[2]
> tickMarks<-round(tickMarks<-seq(b,e,by=(e-b)/6),2)
> axis(2,las=2,at=tickMarks,labels=sprintf("%.2f",tickMarks));
> 
> ______________________________________________
> 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.
> 


      __________________________________________________________________
Looking for the perfect gift? Give the gift of Flickr! 

http://www.flickr.com/gift/




More information about the R-help mailing list