Hello!! I am trying to get the sum values at the top of each bar and I am having some trouble. My code is as follows:
load("H:\\Personal\\provider1.csv")
d=read.csv("provider1.csv", header=T)
library(ggplot2)
library(dplyr)
totals<- d %>%
group_by(Date) %>%
summarise(total=sum(Appointments))
ggplot(d, aes(fill=Provider, y=Appointments, x=Date)) +
geom_bar(position="stack", stat="identity") +
geom_text(aes(label=Appointments, totals))
I get an error with this code:
Error: Aesthetics must be either length 1 or the same as the data (32): x
Run rlang::last_error() to see where the error occurred.
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 ...
There are 4 different dates and 8 different providers.
When I don't add the last word of my code, "totals," I can see the bar chart, but the labels are for each different provider and they are all muddled on each bar. I only want the totals at the top.
Thanks for your help!!