I have a dataset:
data <- c('real','real','real','real','real','pred','pred','pred','pred','pred','real','real','real','real','pred','pred','pred','pred')
threshold <- c('>=1','>=2','>=3','>=4','>=101','>=1','>=2','>=3','>=4','>=101','>=1','>=2','>=3','>=4','>=1','>=2','>=3','>=4')
accuracy <- c(63.4,64.4,65.1,64.3,65.4,62.1,63.6,64.1,65.4,64.8,62.2,63.3,64.4,65.6,63.1,63.8,64.6,65.1)
types<-c('morning','morning','morning','morning','morning','morning','morning','morning','morning','morning','evening','evening','evening','evening','evening','evening','evening','evening')
df <- data.frame(data,threshold,accuracy,types)
I want to plot 'data' column as stacked barplot for morning and evening separately. So I use facet wrap. My code for plotting is:
ggplot(df, aes(x = threshold, y = accuracy)) + geom_bar(aes(fill = data), stat = "identity", color = "white",position = position_dodge(0.9))+
facet_wrap(~types) +
fill_palette("jco")
And the plot I get looks like:
However, as you can see the order of threshold got messed up. I want the order for morning to look like:
'>=1','>=2','>=3','>=4','>=101'
And the order for evening should be:
'>=1','>=2','>=3','>=4'
So I have three questions:
- How can I enforce the order using my code?
2 Also for evening I shouldn't be getting '>=101' so how can I remove that from the plot.
Is there a way to make the background white but keep the grid.
And on a slightly unrelated note, can you point at a graph type that might be slightly better looking than this? I am new at visualisation so I am still learning.
Insights will be appreciated.