Trying to order a histogram/barchart by factor number but using factor name as labels

Leon_Shernoff

New Member
I have data on mushroom edibility that looks like this:

SpeciesName Edibility EdibilityRank
abruptibulbus Good 3
arvensis Choice 1
bisporus Good 3
bitorquis Choice 1
campestris Choice 1
diminutivus Presumed harmless 4
fuscofibrillosus Choice non-standard 2
haemorrhoidarius Choice non-standard 2
micromegethus Presumed harmless 4
placomyces Mildly poisonous 5
silvaticus Choice non-standard 2
silvicola Good 3
subrufescens Choice 1

For each species of mushroom (first column) there is an edibility descriptor (second column) and a numerical edibility ranking (third column) with the lower a ranking is, the more preferable the mushroom is. There is a one-to-one relationship between the descriptors and the rankings.

I want to produce a barchart/histogram that shows the frequency of each level of edibility, ordered by the rank and labeled on the x-axis with the descriptor. That is, the Edibility variable, while it looks like a nominal/categorical variable, is really ordinal, and I'm trying to find a way to graph it that way.

I can make a barchart/histogram that's ordered alphabetically by the names of the descriptors like this:

Code:
edtable <- table(SourceFile$Edibility) par(mai=c(3,1,1,1)) barplot(edtable, las=2) or by frequency like this: Code: edtable <- table(SourceFile$Edibility)
par(mai=c(3,1,1,1))
barplot(edtable [order(edtable, decreasing = T)], las=2)
but I can't find a way to order the same sort of chart by the numerical rank.

rogojel

TS Contributor
Re: Trying to order a histogram/barchart by factor number but using factor name as la

Check if your Edibility variable is a factor (I assume it is). If yes, you could use the function relevel to change the alphabetical order to any order you want.