-1

Code where I am explicitly ordering by factor(...) into levels but its effect is not observed in Rplots.pdf

# data
# http://stackoverflow.com/a/40694900/54964 

summary(datm)

datm$male.Nij <- factor(datm$male.Nij, c("Sinus", "Arr/AHB", "Digoxin arr", "Furosemide arr"))

summary(datm)

# http://stackoverflow.com/a/6359164/54964
library(lattice)
lvs = unique(dat$male.Nij) # TODO maybe here something?  
barchart(variable ~ value|group + factor(male.Nij, levels=lvs), 
  groups=gender, 
  data=datm, 
  auto.key=list(space='right')
)

Output is correct after datm$male.Nij <- factor(...) but print into Rplots.pdf shows still the original order

          male.Nij     gender             group              variable 
 Arr/AHB       :32   Length:128         Length:128         N11    :16  
 Digoxin arr   :32   Class :character   Class :character   N22    :16  
 Furosemide arr:32   Mode  :character   Mode  :character   N33    :16  
 Sinus         :32                                         N44    :16  
                                                           N21    :16  
                                                           N31    :16  
                                                           (Other):32 
           male.Nij 
 Sinus         :32   
 Arr/AHB       :32   
 Digoxin arr   :32   
 Furosemide arr:32  

Testing user20650's proposal

Code

summary(datm)

barchart(variable ~ value|group + male.Nij, 
  groups=gender, 
  data=datm, 
  auto.key=list(space='right')
)

Output: no change, still wrong output

R: 3.3.2
OS: Debian 8.5

Léo Léopold Hertz 준영
  • 119,377
  • 159
  • 417
  • 655

1 Answers1

0

Answer based on user20650's comments and other iterations

datm$male.Nij <- factor(datm$male.Nij, c("Sinus", "Arr/AHB", "Digoxin arr", "Furosemide arr"))

# http://stackoverflow.com/a/6359164/54964
library(lattice)
lvs = unique(dat$male.Nij) # for ordering facets    
barchart(variable ~ value|group + factor(male.Nij, levels=rev(lvs)),
factor(male.Nij, levels=lvs), 
  groups=gender, 
  data=datm, 
  auto.key=list(space='right')
)

where the application of the first line and rev(lvs) are needed. The behaviour is different in some other R systems, which reason is unknown.

Léo Léopold Hertz 준영
  • 119,377
  • 159
  • 417
  • 655