0

I am attempting to analyse the most expensive to least prescriptions items. There is a table named Prescription2014 that contains 21 sets of chemical groups, group ID, number of dispensed items and NET costs.

In the NET costs column, when I tried to filter it according to the value, it always sorts out alphabetically meaning 1, 2, 3, 4 format. E.g. it sorts out like 10, 200, 3, 44, however it has to be 3, 10, 44, 200.

The code that I am using is

library(ggplot2)
cc <- ggplot(prescription2014, aes(x = reorder(as.numeric(Prescription.ID), 
      Prescription.items.dispenses.thousands.), 
      y = as.character(Net.ingredient.cost.thousands.), 
      fill = Prescription.items.dispenses.thousands.)) + geom_bar(stat = "identity") 
cc 

Here, I have set Net.ingredient.cost.thousands as character because I want to show the value of the money in the graph so that the viewer can clearly see the cost of items.

Thank you

enter image description here

Sandesh Rana
  • 81
  • 4
  • 13

1 Answers1

0

Try making your example reproducible using some generic data, or a subset of your prescription2014 object.

It sounds like your sorting variable might be a character when it should be a numeric, but we can't tell from your code. Try converting your variable to numeric using as.numeric(your_variable).

Bryan
  • 933
  • 1
  • 7
  • 21
  • So you mean like this? x <- as.numeric(prescription2014$Prescription.ID) y <- as.numeric(prescription2014$Net.ingredient.cost.thousands.) cc <- ggplot(prescription2014, aes(x = reorder(x, Prescription.items.dispenses.thousands.), y = y, fill = Prescription.items.dispenses.thousands.)) + geom_bar(stat = "identity") It gives me the same graph after this change – Sandesh Rana Aug 11 '15 at 22:01
  • For details on how to make a reproducible example, see [this post](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). You will want to use `dput` to provide your data. Otherwise it's impossible to troubleshoot the problem. – Bryan Aug 11 '15 at 23:14