[R] Orientation of tickmarks labels in boxplot/plot

Marc Schwartz (via MN) mschwartz at mn.rr.com
Wed Nov 2 23:47:50 CET 2005


On Wed, 2005-11-02 at 16:06 -0600, Michal Lijowski wrote:
> Hi,
> 
> I have been trying draw tickmark labels along
> the y - axis perpendicular to the y axis while
> labels along the x - axis parallel to x axis
> while making box plot.
> 
> Here is my test dataset.
> 
>  TData
>    ID Ratio
> 1   0 7.075
> 2   0 7.414
> 3   0 7.403
> 4   0 7.168
> 5   0 6.820
> 6   0 7.294
> 7   0 7.238
> 8   0 7.938
> 9   1 7.708
> 10  1 8.691
> 11  1 8.714
> 12  1 8.066
> 13  1 8.949
> 14  1 8.590
> 15  1 8.714
> 16  1 8.601
> 
>  boxplot(Ratio ~ ID, data=TData)
> 
> makes box plot with tickmark labels parallel to the y - axis.
> So I try 
> 
> boxplot(Ratio ~ ID, data=TData, axes=FALSE)
> par(las=0)
> axis(1)
> and I get x - axis ranging from 0.5 to 2.5 (why?) and 
> boxes at 1 and 2.
> par(las=2)
> axis(2)
> box()
> So, if I set tickmark labels parallel to y - axis
> somehow the x - axis range is not what I expect even
> if I use xlim = c(0.0, 3.0)
>  in boxplot(Ratio ~ Id, data=TData, axes=FALSE, xlim=c(0.0, 3.0))
>  par(las=0)
>  axis(1)
> 
> Plots are in the attachments in pdf format.
> 
> I appreciate any tips.
> 
> I am using R 2.2.0 (2005-10-06) on FC4.
> 
> Michal

I suspect that you want this:

  boxplot(Ratio ~ ID, data=TData, las = 1)

so that the x and y axis labels are horizontal. See ?par and review the
options for 'las'. '1' is for axis tick mark labels to be horizontal.

The x axis (horizontal axis if the boxes are vertical, the vertical axis
if the boxes are horizontal) is set by default to the number of boxes
(groups) +/- 0.5.  'xlim' is ignored in both cases.

The boxes themselves are placed at integer values from 1:N, where N is
the number of groups.

There is the 'at' argument and there is an example of its use
in ?boxplot. You can also search the archives for posts where variations
on the use of 'at' have been posted (recently, in fact...)

The actual plotting of the boxplots is done by bxp(), so review the help
for that function as well.

HTH,

Marc Schwartz




More information about the R-help mailing list