[R] changing y-axis intervals in a boxplot

Jim Lemon jim at bitwrit.com.au
Fri Mar 29 12:23:57 CET 2013


And if you would like to be able to read the crowded axis:

boxplot(count ~ spray, data = InsectSprays, col = "lightgray", yaxt='n')
library(plotrix)
staxlab(2, at=seq(0,25,1),cex=0.8)

Jim


On 03/29/2013 08:36 PM, Pascal Oettli wrote:
> Hi,
>
> Example adapted from ?boxplot
>
> par(las=1, mfrow=c(2,1))
> boxplot(count ~ spray, data = InsectSprays, col = "lightgray", yaxt='n')
> axis(2, at=seq(0,25,2.5))
> boxplot(count ~ spray, data = InsectSprays, col = "lightgray", yaxt='n')
> axis(2, at=seq(0,25,1))
>
> HTH,
> Pascal
>
>
> On 29/03/13 18:22, Berg, Tobias van den wrote:
>> Thank you Pascal but unfortunelately i still didn't figure out how to
>> change the numbers presented at the y-axis.
>>
>> I looked up your suggestions but if I'm right, yaxt can set if the
>> axis is presented (yaxt="s") or suppressed (yaxt="n") which does not
>> help for changing the values on the y-axis.
>>
>> The 'at' argument did solve my problem but in a clumsy way. Although
>> I'm happy that I managed, does anyone know how to do the same job in a
>> more convenient way?
>>
>> This is the 'clumsy' code I used:
>>
>> boxplot((fitted(finalfit4) *100) ~
>> instabilitydata2$MRI_Diag_Instab_rev, ylim=c(0,100), xlab="MRA
>> diagnosis", ylab="Predicted probability (%)")
>> axis(side=2, at="10")
>> axis(side=2, at="30")
>> axis(side=2, at="50")
>> axis(side=2, at="70")
>> axis(side=2, at="90")
>>
>> Kind regards,
>>
>> Tobias
>>
>> -----Oorspronkelijk bericht-----
>> Van: Pascal Oettli [mailto:kridox at ymail.com]
>> Verzonden: vrijdag 29 maart 2013 8:44
>> Aan: Berg, Tobias van den
>> CC: 'r-help at r-project.org'
>> Onderwerp: Re: [R] changing y-axis intervals in a boxplot
>>
>> Hello,
>>
>> ?par (particularly the 'yaxt' argument)
>> ?axis ('side' and 'at' arguments)
>>
>> Hope this help,
>> Pascal
>>
>>
>>
>> On 29/03/13 16:37, Berg, Tobias van den wrote:
>>> Dear R-users,
>>>
>>> I'm a bit of a rooky in R and do not know how to change the y-axis
>>> intervals of a boxplot.
>>>
>>> The y-axis in my boxplot ranges from 0 to 100 which is fine. The
>>> problem is the interval level in between. Now it increases with steps
>>> of 20 but I'd like to have it changed by steps of 5.
>>>
>>> Anyone knows how to do this in R?
>>>
>>> I used the following code for producing this boxplot:
>>> boxplot((fitted(finalfit4) *100) ~
>>> instabilitydata2$MRI_Diag_Instab_rev, ylim=c(0,100), xlab="MRA
>>> diagnosis", ylab="Predicted probability (%)")
>>>
>>>
>>> Kind regards, Tobias



More information about the R-help mailing list