-1

Can someone shed some light on how to order the following bar plot:

day<-c('Sun','Mon','Tue','Wed','Thur','Fri','Sat')
value<-c(13,100,45,32,56,78,65)

df<-data.frame(day,value)
df<-df[order(value),]


ggplot(df) +
  geom_bar(aes(y=tot, x=day,fill=day), stat="identity")+
  labs(title=paste( "bar plot")) +ylab("y")+xlab("x")+theme(plot.title = element_text(hjust = 0.5))

Thanks!

Achilles
  • 11
  • 2

1 Answers1

-1

Try this:

library(tidyverse)

day<-factor(c('Sun','Mon','Tue','Wed','Thur','Fri','Sat'),
            levels = c('Sun','Mon','Tue','Wed','Thur','Fri','Sat'),
            ordered = T)
value<-c(13,100,45,32,56,78,65)

df<-data.frame(day,value)

#By day
ggplot(df) +
  geom_bar(aes(y=value, x=day,fill=day), stat="identity")+
  labs(title=paste( "bar plot")) +ylab("y")+xlab("x")+theme(plot.title = element_text(hjust = 0.5))

enter image description here

#By value
ggplot(df,aes(y=value, x=reorder(day,value),fill=day)) +
  geom_bar(stat="identity")+
  labs(title=paste( "bar plot")) +ylab("y")+xlab("x")+theme(plot.title = element_text(hjust = 0.5))

enter image description here

Duck
  • 39,058
  • 13
  • 42
  • 84