[R] Sorting of captions on axes

Duncan Murdoch murdoch at stats.uwo.ca
Fri Jan 4 17:12:58 CET 2008


On 1/4/2008 10:44 AM, mika03 wrote:
> 
> Hello,
> 
> I think this might be a beginner question, but I couldn't find the answer in
> the manual...
> 
> 
> http://www.nabble.com/file/p14618947/at-modality.png 
> 
> 
> I created this image with R by using the following code:
> 
> 
> modality <- read.table("results.table", header=TRUE, sep=",")
> color <- c("red3","green3","blue3","orange2","purple2","brown4")
> plot(modality, col=color)
> 
> The data I read in has this format:
> ...
> 38355  GeneralInfo      Textual
> 38356  GeneralInfo      Textual
> 38357       Person      Textual
> 38358       Person  Combination
> 38359       Advice      Textual
> 38360  GeneralInfo      Textual
> ...
> 
> 
> The plot is exactly what I want, except for the sorting of the captions on
> the axes.
> 
> I want to have them in a specfic order which is for the x-axis: Textual,
> Graphic, Video, Combination
> The y-axis shoul also sorted in different way, moreover some labels are
> missing here, that's not good!
> 
> Does anyone know how to fix this?

You didn't give enough code to reproduce your plot, but generally the 
idea would be to replace the factor that's in the wrong order with an 
ordered factor in your chosen order, with something like

modality$col3 <- ordered(modality$col3, levels=c("Textual", "Graphic", 
"Video", "Combination"))

(Put the actual column name in place of col3 above.)

Duncan Murdoch




More information about the R-help mailing list