njtierney / naniar

Tidy data structures, summaries, and visualisations for missing data
http://naniar.njtierney.com/
Other
650 stars 54 forks source link

shape mapping Object ..missing.. not found #290

Closed maksymiuks closed 1 year ago

maksymiuks commented 3 years ago

Hi!

First of all thank you for your amazing job under this package. I consider it great and love to see how it develops. I have one slight issue to consult though and I probably need a hand with that. It is slightly related to the issue https://github.com/njtierney/naniar/issues/137. To cut long story short mapping works perfectly for color as you can see below but it fails for shape with an error Object ..missing.. not found (in English version may be slightly different, I translated it myself from my local). Do you have any idea what caused that? Use case of mine is that color mapping is not specified (desired is default one) while the shape is specified and second use case is when both are specified. Do you have any idea what might have causedd a problem?

Best Szymon

data <- DALEX::apartments
data <- missForest::prodNA(data)
data$no.rooms <- as.factor(data$no.rooms)

library(ggplot2)
library(naniar)

ggplot(data = data, mapping = aes(.data$m2.price, .data$surface)) +
  geom_miss_point()

ggplot(data = data, mapping = aes(.data$m2.price, .data$surface, color = .data$district)) +
  geom_miss_point()

ggplot(data = data, mapping = aes(.data$m2.price, .data$surface, shape = .data$no.rooms)) +
  geom_miss_point()
#> Warning: Failed to apply `after_scale()` modifications to legend
#> Error in FUN(X[[i]], ...): Object '..missing..' not found

Created on 2021-09-03 by the reprex package (v2.0.1)

Additionally, I have one small question. Is it possible to make elements in ..missing. (when using geom with default settings) a factor with Missing and Not Missing levels? That way they will be always of the same color instead of swapping colors depending on if the data have or don't have missing values. It is really confusing.

jonocarroll commented 2 years ago

I haven't been able to get my head around how ggproto works enough to offer any suggestions for how to fix this, but a workaround might be to use stat_miss_point() which seems to work as a drop-in replacement, at least for the above example and others I tried (whether that's right or wrong is beyond my knowledge)

## using above construction
ggplot(data = data, mapping = aes(.data$m2.price, .data$surface, shape = .data$no.rooms)) +
  stat_miss_point()

stat_miss_point

## using construction in #137
mydat <- mtcars
mydat$mpg[1:10] = NA
ggplot(mydat, aes(x = mpg, y = disp, shape = factor(cyl))) +
  stat_miss_point(size = 4)

stat_miss_point_mtcars

Is there any reason one shouldn't do this?

Additionally, when the aesthetic variable is missing there's an additional layer of 'missingness' to deal with and I wonder if that should be handled by making 'missing' a new level of that scale?

dicook commented 2 years ago

I think that is a good idea, actually the convention recommended when you have a missng value for a categorical variable. Encode it as an additional category.

On 21 Sep 2021, at 11:41 am, Jonathan Carroll @.***> wrote:

I haven't been able to get my head around how ggproto works enough to offer any suggestions for how to fix this, but a workaround might be to use stat_miss_point() which seems to work as a drop-in replacement, at least for the above example and others I tried (whether that's right or wrong is beyond my knowledge)

using above construction

ggplot( data = data, mapping = aes(.data$m2.price, .data$surface, shape = .data$no.rooms)) +

stat_miss_point()

using construction in #137

mydat <- mtcars mydat$mpg[1:10] = NA

ggplot( mydat, aes(x = mpg, y = disp, shape = factor(cyl))) +

stat_miss_point( size = 4)

Is there any reason one shouldn't do this?

Additionally, when the aesthetic variable is missing there's an additional layer of 'missingness' to deal with and I wonder if that should be handled by making 'missing' a new level of that scale?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

cheers, Di


Dianne Cook @.***

njtierney commented 1 year ago

Thank you @jonocarroll and @maksymiuks ! This has been closed in #293