From the online bar chart guide:
qplot(factor(cyl), data=mtcars, geom="bar", fill=factor(gear))
How do I get 5 to sit on the bottom, 4 above that, and 3 on top?
Under Chart Tools, on the Design tab, in the Data group, click Select Data. In the Select Data Source dialog box, in the Legend Entries (Series) box, click the data series that you want to change the order of. Click the Move Up or Move Down arrows to move the data series to the position that you want.
To reorder bars manually, you have to pass stat=”identity” in the geom_bar() function.
To reorder the boxplot we will use reorder() function of ggplot2. By default, ggplot2 orders the groups in alphabetical order. But for better visualization of data sometimes we need to reorder them in increasing and decreasing order. This is where the reorder() function comes into play.
qplot(factor(cyl), data=mtcars, geom="bar", fill=factor(gear), order = -gear)
qplot(factor(cyl), data=mtcars, geom='bar', fill=factor(gear, level=5:3))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With