R: Plot: Re-arranging the order of variables -
i want create barplot in r. however, re-arrange variables on x-axis, not frequency 'meaning'.
imagine have following data set:
df<-data.frame(read.table(header=true, text=" id radio 1 2 b 3 4 c 5 d 6 d 7 e 8 e 9 10 b 11 c 12 e 13 c 14 15 d 16 17 c 18 19 20 f 21 22 c 23 c 24 25 b 26 27 c 28 29 b 30 c"))
i want use plot
depict frequencies.
plot(df$radio)
obviously, r create barplot, ordered levels of factor df$radio
(i.e. a
b
c
d
e
f
). let us, however, assume, order should be: c
e
b
a
d
f
. (in real-case case behind scenario variable dr$radio
stands the last time respondent has been using radio. c
stands 'today', e
'last week' etc.)
i not sure re-arrange order in barplot. tried re-arrange order of levels of df$radio. however, messed factor variable. also, tried solve problem using `order' in plot-code no avail, too. ideas? appreciated!
we can use factor
levels
specified
plot(factor(df$radio, levels=c("c", "e", "b", "a", "d", "f")))
Comments
Post a Comment