[R] Order of Dotplot output
allison at soundgis.com
Fri Oct 19 23:40:26 CEST 2007
Thanks for the suggestions. The factor function on the RYEAR column worked well.
I need to clarify my question about the order of the plot. as.table appears to be concerned with the order that each panel is plotted. Is that correct?
I'm interested in controlling the order of the elements on the y-axis of the graph. Right now, the species are listed in reverse alphabetical order. I'm interested in having them in alphabetical order or in order by the magnitude of their values (highest on the top, to lowest on the bottom). Any additional suggestions?
Deepayan Sarkar wrote:
> 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
> dotplot(CNAME ~ RR | factor(RYEAR), <...> )
More information about the R-help