The key with ordering is to set the levels of the factor in the order you want. An ordered factor is not required; the extra information in an ordered factor isn't necessary and if these data are being used in any statistical model, the wrong parametrisation might result — polynomial contrasts aren't right for nominal data such as this.
## set the levels in order we want theTable <- within(theTable, Position <- factor(Position, levels=names(sort(table(Position), decreasing=TRUE)))) ## plot ggplot(theTable,aes(x=Position))+geom_bar(binwidth=1)
In the most general sense, we simply need to set the factor levels to be in the desired order. If left unspecified, the levels of a factor will be sorted alphabetically. However, there are multiple ways to change the order to a specific sequence depending on the situation. For instance, we could do:
levels(theTable$Position) <- c(...)
and simply list the levels in the desired order on the right hand side. You can also specify the level order within the call to factor as above:
theTable$Position <- factor(theTable$Position, levels = c(...))