Order days in Jitter Plot

112 views Asked by At

I have one data set with two columns (Weekdays and Sales).So my intention is to make jitter plot with ggplot2. You can see data set below.

#DATA

library(ggplot2)
     INPUT_MATRIX_FINAL_GRAPH_test<-structure(list(Weekdays = c("Tuesday", "Thursday", "Thursday", 
                                        "Saturday", "Wednesday", "Sunday", "Friday", "Wednesday", "Sunday", 
                                        "Thursday", "Tuesday", "Friday", "Sunday", "Thursday", "Monday", 
                                        "Thursday", "Friday", "Saturday", "Sunday", "Thursday", "Tuesday", 
                                        "Wednesday", "Tuesday", "Friday", "Saturday", "Tuesday", "Monday", 
                                        "Friday", "Sunday", "Tuesday", "Wednesday", "Wednesday", "Sunday", 
                                        "Monday", "Tuesday", "Tuesday", "Thursday", "Wednesday", "Friday", 
                                        "Thursday", "Monday", "Tuesday", "Thursday", "Saturday", "Tuesday", 
                                        "Friday", "Sunday", "Saturday", "Sunday", "Tuesday", "Tuesday", 
                                        "Friday", "Friday", "Wednesday", "Saturday", "Friday", "Thursday", 
                                        "Friday", "Wednesday", "Wednesday", "Friday", "Friday", "Sunday", 
                                        "Saturday", "Friday", "Thursday", "Monday", "Wednesday", "Tuesday", 
                                        "Sunday", "Thursday", "Sunday", "Monday", "Thursday", "Tuesday", 
                                        "Thursday", "Sunday", "Saturday", "Tuesday", "Wednesday", "Wednesday", 
                                        "Monday", "Saturday", "Monday", "Tuesday", "Thursday", "Friday", 
                                        "Friday", "Sunday", "Tuesday", "Monday", "Saturday", "Wednesday", 
                                        "Thursday", "Friday", "Thursday", "Thursday", "Tuesday", "Friday", 
                                        "Friday", "Sunday", "Tuesday", "Tuesday", "Thursday", "Friday", 
                                        "Monday", "Wednesday", "Sunday", "Sunday", "Thursday", "Tuesday", 
                                        "Tuesday", "Monday", "Wednesday", "Friday", "Friday", "Wednesday", 
                                        "Thursday", "Wednesday", "Sunday", "Monday", "Tuesday", "Wednesday", 
                                        "Saturday", "Saturday", "Tuesday", "Sunday", "Thursday", "Thursday", 
                                        "Friday", "Sunday", "Sunday", "Wednesday", "Friday", "Monday", 
                                        "Saturday", "Monday", "Tuesday", "Saturday", "Monday", "Friday", 
                                        "Tuesday", "Wednesday", "Sunday", "Saturday", "Wednesday", "Thursday", 
                                        "Tuesday", "Saturday", "Tuesday", "Tuesday", "Tuesday", "Sunday", 
                                        "Thursday", "Thursday", "Thursday", "Monday", "Saturday", "Friday", 
                                        "Monday", "Sunday", "Tuesday", "Sunday", "Monday", "Saturday", 
                                        "Tuesday", "Monday", "Sunday", "Thursday", "Wednesday", "Thursday", 
                                        "Friday", "Thursday", "Friday", "Saturday", "Friday", "Friday", 
                                        "Thursday", "Saturday", "Tuesday", "Sunday", "Monday", "Friday", 
                                        "Tuesday", "Friday", "Sunday", "Sunday", "Sunday", "Tuesday", 
                                        "Friday", "Thursday", "Wednesday", "Wednesday", "Monday", "Saturday", 
                                        "Wednesday", "Monday", "Sunday", "Monday", "Wednesday", "Thursday", 
                                        "Saturday", "Saturday", "Tuesday", "Wednesday", "Saturday", "Friday", 
                                        "Monday", "Thursday", "Thursday"), Sales = c(15.9, 16.2, 22.7, 
                                                                                     0, 13.5, 0, 31.3, 13.6, 0, 13, 59.1, 0, 0, 9.9, 29.4, 22.1, 22.4, 
                                                                                     0, 0, 13.4, 19.9, 19, 0, 32.3, 0, 15.1, 0, 24.9, 0, 15.7, 17, 
                                                                                     12, 0, 30.5, 26.6, 0, 23.3, 24.7, 19.7, 27.7, 20.4, 11.4, 20.7, 
                                                                                     0, 23.3, 20.1, 0, 0, 0, 0, 18.1, 14.9, 31.9, 25.5, 0, 24.8, 19, 
                                                                                     17.3, 23.2, 23.1, 16.6, 23.4, 0, 0, 26, 17.6, 22.4, 14.6, 16.2, 
                                                                                     0, 11, 0, 0, 19.8, 19.1, 18.2, 0, 0, 18.8, 0, 14.2, 25.7, 0, 
                                                                                     18.1, 18.6, 19.4, 13.7, 23.5, 0, 72, 18.6, 0, 21.6, 11.1, 14.3, 
                                                                                     21.1, 21.4, 20.6, 25, 23.4, 0, 12.5, 48.7, 25, 15.7, 25, 12.2, 
                                                                                     0, 0, 23.7, 13.4, 17.3, 19.9, 17.3, 18.4, 18.3, 15.2, 25, 21.1, 
                                                                                     0, 25.8, 16.4, 20.5, 0, 0, 14.7, 0, 18.8, 28, 0, 0, 0, 6.4, 28.5, 
                                                                                     0, 0, 23.5, 21, 3.3, 0, 22.4, 21.1, 16.4, 0, 0, 31.8, 21, 14.4, 
                                                                                     0, 25, 16.7, 0, 0, 12.7, 18.7, 14, 22.6, 0, 31.1, 43.2, 0, 19.7, 
                                                                                     0, 25, 0, 17.9, 14.3, 0, 17.3, 13.4, 16.2, 13.7, 21.2, 26.4, 
                                                                                     0, 30.1, 24.5, 18.8, 0, 22.5, 0, 20.9, 0, 16.7, 22.7, 0, 0, 0, 
                                                                                     16.6, 19.7, 18.2, 14.7, 11.7, 16.6, 0, 16.2, 22.3, 0, 19.3, 14.4, 
                                                                                     0, 0, 0, 11.4, 13, 0, 22.9, 24, 19.7, 15)), row.names = c(NA, 
                                                                                                                                               -210L), class = "data.frame")

So next step is making jitter plot with this line of code

qplot(Weekdays,Sales,data=INPUT_MATRIX_FINAL_GRAPH_test,geom = "jitter")

So far so good:) But here arise a new problem for me. Namely days are not ordering correct and my next steep should be how to order by names of days correct (e.g Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday)

enter image description here

So can anybody help me how to resolve this problem ?

1

There are 1 answers

0
dc37 On BEST ANSWER

You can use scale_x_discrete and order days by passing the right order into limits argument:

qplot(Weekdays,Sales,data=INPUT_MATRIX_FINAL_GRAPH_test,geom = "jitter")+
  scale_x_discrete(limits = c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"))

enter image description here