Missing values (position_stack)

hey!
I had this graph all ready and working last week; however, today when I went back and changed a couple of data points and then when to update the graph, I have been getting this warning message:

Warning message:
Removed 32 rows containing missing values (position_stack).

My code is as follows:

load("H:\\Personal\\provider3.csv")
d=read.csv("provider3.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 %>%
	mutate(Date = factor(Date,
		levels = c("Jan-20", "Feb-20", "Jun-20", "Jul-20"))) %>%

ggplot(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_minimal() + 
	theme(text=element_text(size=18))

Here is a small sample of my data:

'data.frame':   32 obs. of  3 variables:
 $ Provider    : chr  "MW" "JA" "IR" "AV" ...
 $ Date        : Factor w/ 4 levels "20-Feb","20-Jan",..: 1 1 1 1 1 1 1 1 2 2 ...
 $ Appointments: int  69 66 54 66 0 6 17 14 81 80 ...

Last week my graph looked like this:

Now, it looks like this:

start by understanding how NA' values got into your data.
one way to find them is

missing_rows<- filter_all(d %>%
	mutate(Date = factor(Date,
		levels = c("Jan-20", "Feb-20", "Jun-20", "Jul-20"))), any_vars(is.na(.)))

its complicated because you don't store the post manipulated d that goes into ggplot

d_to_plot <- d %>%
	mutate(Date = factor(Date,
		levels = c("Jan-20", "Feb-20", "Jun-20", "Jul-20"))) 

ggplot(data=d_to_plot,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_minimal() + 
	theme(text=element_text(size=18))

in which case you would analyse

missing_rows<- filter_all(d_to_plot, any_vars(is.na(.)))

thats not to say totals shouldnt be explored

Thanks for your help!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.