'How to use na.omit with ggplot

Database

The image shows the database, it starts with day 0 and ends with day 14. In between these, there are empty values for what I am plotting. I am unable to correctly use na.omit().

What I get currently is this:

Current graph

As you can see, half of it should not be there. So i could limit the axis to show only part of it, But i might have data every other day. So omitting NAs is the best option. The code is as follows:

T <- USP20019 %>%
ggplot(aes(Cell_line, Capsids)) +
geom_col(aes(fill=Day), size=1.1, position = 'dodge2') +
facet_wrap(Condition~., scales = 'free_x') +
ylab('Titer mg/L') +
xlab('Time (Day)') +
ggtitle('All data') +
theme(strip.text.x = element_text(size = 12), axis.title = element_text(size = 14), axis.text = element_text(size = 14), legend.position = "none")


Solution 1:[1]

You should use subset inside ggplot2.

T <- ggplot(subset(USP20019, !is.na(Capsids)) , aes(Cell_line, Capsids)) + ...

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 YBS