Reputation: 27
I tried to use "ggplot" to create a bar chart to summary this dataset. Here are my codes:
ggplot(dat3,aes(variable,value,fill=Industries))+geom_bar(stat="identity",position=
"dodge")+scale_fill_brewer(palette = "Set1")
As we can see, the scale of value looks messy, it doesn't follow the order. How can I fix it?
Upvotes: 0
Views: 400
Reputation: 33782
The main problem here is that the value
column is not numeric. It contains commas which would make it a character variable - but unless you specify stringsAsFactors = FALSE
when you import the data, the values are converted to a factor (as you can see by the <fctr>
at the top of the column).
The quickest fix is to convert that column to character, remove the commas, then convert to numeric:
dat3$value <- as.character(dat3$value)
dat3$value <- gsub(",", "", dat3$value)
dat3$value <- as.numeric(dat3$value)
You should also decide whether you want Industries
and variable
to be factors.
Upvotes: 2