0

I want to plot a grouped graph in ggplot in R but don't want the NA to show.

I have the following code:

lusl %>%
  ggplot(aes(wave, generalhealth)) + geom_point(alpha = .005) +
  stat_summary(aes(color = harassment_fct, group = harassment_fct),
                fun.y = mean, geom = "line", lwd = 1.5) +
  labs(x = "Wave", y = "GHQ-12 Value", color = "Experience of Racial Harassment")

And I get the following graph:

enter image description here

How do I get rid of the NA?

Nora17.06
  • 25
  • 3
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Aug 24 '21 at 18:34

1 Answers1

0

Without a reproducible example and understanding the structure of your database, a simple option is to use drop_na() to remove any row containing NA values.

lusl %>% 
  drop_na() %>%
  ggplot(aes(wave, generalhealth)) + geom_point(alpha = .005) # etc.

If you want a more precise removal of the NA values, only in harassment_fct (used for color), then filter these out:

lusl %>% 
  filter(!is.na(harassment_fct)) %>%
  ggplot(aes(wave, generalhealth)) + geom_point(alpha = .005) # etc.
  
iNyar
  • 1,916
  • 1
  • 17
  • 31