1

enter image description here

I would like to order the bars as Monday, Tuesday, Wednesday...Sunday instead of a random order. I also would like to display the full numbers on the Y axis instead of 1e+05.

#code snippet
DaysCrime <- ggplot(TrainCrime, aes(DayOfWeek))

DaysCrime + geom_histogram(colour = "darkblue", fill = "lightblue")
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Prasanth Regupathy
  • 882
  • 10
  • 11

1 Answers1

2

We can convert it to factor and specify the levels order accordingly.

TrainCrime$DayOfWeek <- factor(TrainCrime$DayOfWeek, 
   levels = as.character(wday(c(2:7,1), label=TRUE, abbr=FALSE)))

library(ggplot2) 
DaysCrime <- ggplot(TrainCrime, aes(DayOfWeek))
DaysCrime +
       geom_histogram(colour = "darkblue", fill = "lightblue")

data

v1 <- as.character(wday(1:7, label=TRUE, abbr=FALSE))
set.seed(24)
TrainCrime <- data.frame(DayOfWeek = sample(v1, 100, 
    replace=TRUE), stringsAsFactors=FALSE)
akrun
  • 874,273
  • 37
  • 540
  • 662