Note that there are some explanatory texts on larger screens.

plurals
  1. POCan boxplot in base R display 'NA' when the grouping factor has missing values?
    primarykey
    data
    text
    <p>I want this: </p> <p><img src="https://i.stack.imgur.com/xr0S0.png" alt="a boxplot with NA as a category name"></p> <p>And I thought that passing <code>na.action=na.pass</code> to boxplot would let NA show up in the grouping names. Here is some sample code: </p> <pre><code>#Build a fake dataset set.seed(212012) nn = 100 sample_data &lt;- data.frame( score = c( rpois(nn, 1), rpois(nn, 2), rpois(nn, 1.5), rpois(nn, 3)), category = c( rep(0, nn), rep(1, nn), rep(2, nn), rep(NA, nn) )) boxplot( score ~ category, data=sample_data, na.action=na.pass ) </code></pre> <p>But that produces this: </p> <p><img src="https://i.stack.imgur.com/vuujA.png" alt="enter image description here"></p> <p>The 'simple' way to get what I want is the following code, but it's not great for exploratory data analysis: </p> <pre><code>sample_data$category2 &lt;- sample_data$category sample_data$category2[ is.na(sample_data$category) ] &lt;- 'NA' boxplot( score ~ category2, data=sample_data ) </code></pre> <p>Any hints from the R Guru's out there? I was able to find out about na.pass from <a href="https://stackoverflow.com/questions/5557676/what-are-the-options-for-na-action-in-boxplot">this more general discussion</a>, and the origin of na.pass from <a href="https://stat.ethz.ch/pipermail/r-devel/2004-May/029589.html" rel="nofollow noreferrer">Prof. Ripley here</a>. But there doesn't seem to be a distinction between missing data (NA's) appearing in the data that will be split by the factor and missing data in the factor itself. Am I missing something simple, or is this more of a feature request? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload