How do you take care of variable with missing values when plotting?

27 views
Skip to first unread message

humphrey kimani

unread,
Jul 27, 2018, 10:06:33 AM7/27/18
to ggp...@googlegroups.com, lorine odawa
Hello,

I have a problem.. 

I have been plotting some data here..of gender( Female and Male).. you will find in the data were missing gender.. when I am plotting eg a bar graph I get 3 bar- I expected 2 but its graphing those with missing gender as a variable...I don't want then to be included when am graphing. 
Would any one help me how to go about it..

Regards

Humphrey & Lorine

Ron Crump

unread,
Jul 27, 2018, 11:00:23 AM7/27/18
to humphrey kimani, ggp...@googlegroups.com, lorine odawa
Hi Humphrey,
It would help us to help you if you could produce a small reproducible
example: data and code that illustrate the issue. Not neccesarily your
actual data, if that is private or overly large. The package 'reprex'
can help you ith this, but setting up some data including it via dput
in the email along with code that you've used on this data set would
help.

Regards,
Ron.

Tom Fritzsche

unread,
Jul 27, 2018, 12:17:49 PM7/27/18
to humpk...@gmail.com, ggp...@googlegroups.com, lorin...@gmail.com
Hi Humphrey & Lorine,

I believe ggplot will by default plot all levels of a factor including NAs.

To exclude the cases/lines with NAs for gender, do something like this
and then plot the new object.
This code assumes one data frame (df) with a column named 'gender'
where you coded FEMALE, MALE and have the NAs.

df2 <- df[!is.na(df$gender), ]

Hope this helps
Tom

---

Tom Fritzsche
University of Potsdam
Department of Linguistics
Karl-Liebknecht-Str. 24-25
14476 Potsdam
Germany

office: 14.140
phone: +49 331 977 2296
fax: +49 331 977 2095
email: tom.fr...@uni-potsdam.de
web: www.ling.uni-potsdam.de/~fritzsche
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Nabin Paudel

unread,
Jul 27, 2018, 12:17:49 PM7/27/18
to r.e....@warwick.ac.uk, humpk...@gmail.com, ggp...@googlegroups.com, lorin...@gmail.com
Hi, 

This StackOverflow post may answer your query.


Best Wishes,

Nabin 

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Nabin Paudel, PhD
Postdoctoral Researcher
Center for Eye Research Ireland
Dublin Institute of Technology, Dublin, Ireland

Reply all
Reply to author
Forward
0 new messages