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?

s_baldur
  • 29,441
  • 4
  • 36
  • 69
theBotelho
  • 324
  • 1
  • 3
  • 12
  • 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 <- factor(VetA, levels = c("One","Two","Three"))` – 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
  • 69,533
  • 24
  • 154
  • 197