0

I'm fairly new to R and using this forum, so I apologize for any lack of info and specificity in my question, but how do I remove the NAs from my ridgeline ggplot graph? Here is what I have so far, as well as a link to the picture of my graph:

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

  • 1
    It would be easier to help if you create a small reproducible example along with expected output. Read about [how to give a reproducible example](http://stackoverflow.com/questions/5963269). – Ronak Shah May 19 '21 at 04:24

1 Answers1

0

Before plotting your data remove NA's

## 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]),]
MaxMiak
  • 197
  • 1
  • 7