如何在 ggplot 中使用 na.omit
How to use na.omit with ggplot
该图显示了数据库,它从第 0 天开始到第 14 天结束。在这两者之间,我正在绘制的内容为空值。我无法正确使用 na.omit().
我目前得到的是:
如你所见,一半不应该存在。所以我可以限制轴只显示它的一部分,但我可能每隔一天就有数据。所以省略 NA 是最好的选择。代码如下:
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")
您应该在 ggplot2
中使用 subset
。
T <- ggplot(subset(USP20019, !is.na(Capsids)) , aes(Cell_line, Capsids)) + ...
该图显示了数据库,它从第 0 天开始到第 14 天结束。在这两者之间,我正在绘制的内容为空值。我无法正确使用 na.omit().
我目前得到的是:
如你所见,一半不应该存在。所以我可以限制轴只显示它的一部分,但我可能每隔一天就有数据。所以省略 NA 是最好的选择。代码如下:
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")
您应该在 ggplot2
中使用 subset
。
T <- ggplot(subset(USP20019, !is.na(Capsids)) , aes(Cell_line, Capsids)) + ...