How to remove na from ggplot?

Hi! i'm trying to remove na values from a barchart i want to create.

This is my df

>    ID CONSENTIMIENTO EDAD GENERO  FECHA.NAC JPC_VI_GRUPO par JPC_VI_COND cond JPC_VI_COLOR JPC_VI_DECISION1 JPG_VG_VINCULO
> 1   1              1   11      2 30/05/2006           11   1           D    D            N                1              2
> 2   7              1   43      1 10/03/1974           11  NA           D <NA>            V                3              2
> 3   3              1   11      2 24/05/2006           33   2           D    D         <NA>                4              2
> 4   6              1   41      2 05/08/1976           33  NA           D <NA>         <NA>                4              2
> 5   8              1    5      1 28/04/2012            1   3           D    D            V                1              2
> 6  11              1   38      1 27/07/1979            1  NA           D <NA>            N                3              2
> 7   9              1    8      2 08/05/2009           18   4           D    D            V                1              2
> 8  10              1   36      2 24/06/1981           18  NA           D <NA>            N                3              2
> 9  16              1    8      1 03/02/2009           19   5           D    D            V                1              1
> 10 17              1   36      2 12/05/1981           19  NA           D <NA>            N                2              1

This is the code im using for the barchart

>library(tidyverse)
> # count data frame
> df <- var_datos %>%
>   group_by(cond) %>%
>   count(JPG_VG_VINCULO)
> 
> ggplot(df, aes(fill=cond, y=n, x=JPG_VG_VINCULO)) +
>   geom_bar(position="dodge", stat="identity")

Also, this is how it displays with the na i want to omit

What woud happen if you remove the rows having the NA value for the cond variable?

df <- var_datos %>% filter(!is.na(cond)) %>% ...

Perfect! Thanks!

1 Like