Hi! I am trying to rearrange my x-axis in order of date and I want the words instead of numbers; however, it keeps putting it in alphabetical order. My code is as follows:
load("H:\\Personal\\provider1.csv")
d=read.csv("provider1.csv", header=T)
library(ggplot2)
library(dplyr)
library(forcats)
d <- arrange(d,
Date)
d$Date <- forcats::as_factor(as.character(d$Date,format="%b-%Y"))
totals<- d %>%
group_by(Date) %>%
summarise(total=sum(Appointments))
d %>%
dplyr:mutate(Date = factor(Date,
levels = c("Jan-20", "Feb-20", "Jun-20", "Jul-20"))) %>%
ggplot(d, aes(fill=Provider, y=Appointments, x=Date)) +
geom_bar(position="stack", stat="identity") +
geom_text(data=totals, aes(x=Date, label=total, y=total, fill=NULL), nudge_y=10) +
theme(text=element_text(size=18))
I tried to specify the levels argument, but I keep getting an error:
Error in function_list[[i]](value) : object 'dplyr' not found
I am unsure how to solve this, so any help would be great!
Here is a sample of my data:
'data.frame': 32 obs. of 3 variables:
$ Provider : chr "MW, MD" "MW, MD" "MW, MD" "MW, MD" ...
$ Date : chr "Jan-20" "Feb-20" "Jun-20" "Jul-20" ...
$ Appointments: int 81 69 80 93 80 66 81 63 64 54 ...