[R] Order of Dotplot output

Deepayan Sarkar deepayan.sarkar at gmail.com
Fri Oct 19 20:35:14 CEST 2007


On 10/19/07, Allison Bailey <allison at soundgis.com> wrote:
> I'm just learning to work with R, and am having some difficulty controlling the output of my dotplot.
>
> The default order of the function dotchart seems to be the largest value on the bottom and the smallest on the top.  I wanted it in the opposite order (which is how my data frame is currently sorted), so I used the following approach, which works
>
> orderidx <- order(b2000$RR)
> dotchart(b2000$RR[orderidx], labels = b2000$CNAME[orderidx],cex=0.5,xlab = "Proportion of Annual Catch, 2000")
>
> However, the default behavior of the dotplot function (within the lattice library) seems to be to order the data in reverse alphabetical order (A on the bottom, Z on the top).  Can someone provide suggestions for controlling this order?  I would either prefer largest value (top) to smallest value (bottom) or alphabetical order (A top, Z bottom).
>

Use 'as.table=TRUE', as Jim suggested.

> In addition, is there a way to control the labeling of each subplot?   When I use the following code:
>
> dotplot(CNAME ~ RR | RYEAR, data = btwlSubset, xlab = "% of annual catch ")
>
> each subplot gets labeled with the word "RYEAR", rather than the value contained within the RYEAR column, which is what I would like.
>

That will happen by default if RYEAR is a numeric variable, and the
``levels'' are shown if the variable is a factor. So the easiest fix
is

dotplot(CNAME ~ RR | factor(RYEAR), <...> )

-Deepayan



More information about the R-help mailing list