3

Let

vetA <- structure(
  c(1L, 1L, 1L, 3L, 3L, 3L, 3L, 2L, 2L, 2L), 
  .Label = c("Two", "One", "Three"), 
  class = "factor"
)
vetB <- reorder(vetA, c(9,1,2,3,4,8,7,6,10,5))
plot(vetA)
plot(vetB)

The plots show differently.

plot(VetA)

enter image description here

plot(VetB)

enter image description here

However, reading the ?reorder manual, I didn't understand how the function works and how to manipulated it, so I could display the bars in this order One Two Three. Also, I have read this post in which uses reorder. But, it got me more confused because he used as a second argument a vector not with index, but with percent.

So, could you please have some mercy & give me a hand?

sindri_baldur
  • 25,109
  • 3
  • 30
  • 57
theBotelho
  • 184
  • 1
  • 1
  • 10
  • 1
    `reorder()` puts the bars in the order of increasing mean (because that's the default function) of the vector `c(9,1,2,3,4,8,7,6,10,5)`. – user2554330 Feb 24 '18 at 13:44
  • I usually use `factor` rather than `reorder`, which is maybe a little more intuative for simply defining the order you want. `vetB – dww Feb 24 '18 at 13:45

1 Answers1

1

Use factor and specify in which order the levels are. You can also mark the factor as an ordered factor.

vetC <- factor(vetA, levels = c("One", "Two","Three"))
plot(vetC)
Roman Luštrik
  • 67,056
  • 24
  • 151
  • 191