微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从 R 中的 Ridgeline ggplot 中删除 NA

如何解决从 R 中的 Ridgeline ggplot 中删除 NA

我对 R 和使用这个论坛还很陌生,所以我为我的问题中缺乏信息和特异性表示歉意,但是如何从我的山脊线 ggplot 图中删除 NA?这是我到目前为止所拥有的,以及指向我的图表图片链接

library(ggplot2)
library(ggridges)
library(dplyr)

fpdata_cleaned$teeth_removed1 <- factor(fpdata_cleaned$teeth_removed1,levels=c("None","1 to 5","6 or More","All"))

p <- ggplot(fpdata_cleaned,aes(x = sugardrinks,y = teeth_removed1,fill = teeth_removed1)) +
  geom_density_ridges() + 
  theme_ridges() +
  labs(y="Number of Teeth Removed Due to Gum disease",x="Number of Sugary Beverages Consumed per Month") +
  theme(legend.position = "none")

p + coord_cartesian(xlim = c(0,160))

Picture of my current graph

解决方法

在绘制数据之前删除 NA

## Tidyverse approach
library(dplyr)

#To remove all NA's from data 
data %>% drop_na()

#To remove NA's from particular column

data %>% filter( !is.na(column_name))

##Base R approach
#To remove NA's from whole data frame
na.omit(data)

#To remove NA's from particular column in below romoving NA's from 3 column
data[complete.cases(data[,3]),]

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。