Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 208803

How to include bar with NAs in geom_histogram?

$
0
0

I am trying to create a histogram of a continuous variable (1-10) with a bar a little to the side that says how many NAs are in the vector. I am using geom_histogram() from ggplot2. Here is an example:

v <- data.frame(x=c(1, 2, 3, 4, 3, 2, 3, 4, 5, 3, 2, 1, NA, NA, NA, NA))

ggplot(v, aes(x=x)) + 
  geom_histogram()

enter image description here

I have looked through the features of the function but there doesn't seem to be a way to inlcude NAs and haven't found an elegant way of doing it from other questions. Thanks for the help.


Viewing all articles
Browse latest Browse all 208803

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>