'Why is rmarkdown adding NA values to my ggplot when I knit the file?

I've been stuck on a particular problem. I've created an rmd file and everything is how I'd like it, however, when I knit the rmd file into any format (HTML, pdf, word) the rmd.file will produce the ggplots with NA values. On the other hand, if I run the code chunks in the rmd script it comes out how it should do with no NA values. Just to note there are no NA values to begin with. Any suggestions for how I could fix this?

images attached below:

plot 1 before knit

plot 1 after knit

plot 2 before knit

plot 2 after knit



Solution 1:[1]

I can't try it myself without some reproducible example, but have you tried including drop_na() function?

all_trips_v2 %>% 
  drop_na() %>% ...

or maybe below

... arrange(user_type, weekday) %>% 
drop_na() %>% ...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 elidomx