/ / ggplot2 warning: Stacking non ben definito quando ymin! = 0 - r, ggplot2

avviso ggplot2: impilamento non ben definito quando ymin! = 0 - r, ggplot2

Forse la risposta è solo essere avvertiti. Sto attmepting per usare una variabile in scala e centrata per osservare come le osservazioni differiscono dal valore medio. Questa trama è una pratica comune. Ma quando lo faccio ricevo un avvertimento da ggplot2.

Warning messages:
1: Stacking not well defined when ymin != 0

Mi piace avere ggplot2 e il resto del mondofelice e nessun avvertimento mi sta arrivando. Ho cercato di eliminare l'avviso nei seguenti modi e ho cercato SO (vedere i collegamenti in basso per alcune domande più promettenti) per domande correlate. Ancora il mio amico ggplot2 mi sta avvisando.

DOMANDE):

  1. Come posso far sparire l'avvertimento?
  2. Posso ignorare l'avviso?
  3. C'è qualcosa di sbagliato in questa pratica?

Tentativi di codice:

## The data
mtcars$scaled_mpg <- unlist(tapply(mtcars$mpg, mtcars$cyl, scale))
mtcars <- mtcars[order(mtcars$cyl), ]
mtcars$ID <- unlist(tapply(mtcars$cyl, mtcars$cyl, seq_along))
mtcars$ID <- factor(sprintf("%02d", mtcars$ID ))

##  ================ Attempt 1 ================
ggplot(mtcars, aes(x = ID, y = scaled_mpg, fill = factor(cyl))) +
geom_bar(stat="identity") + facet_grid(cyl~.)

##  ================ Attempt 2 ================
ggplot(mtcars, aes(x = ID, fill = factor(cyl))) +
geom_bar(aes(weight = scaled_mpg)) + facet_grid(cyl~.)

##  ================ Attempt 3 ================
dat1 <- subset(mtcars, scaled_mpg >= 0)
dat2 <- subset(mtcars, scaled_mpg < 0)

ggplot() +
geom_bar(data = dat1, aes(x = ID, y = scaled_mpg,
fill = factor(cyl)),stat = "identity") +
geom_bar(data = dat2, aes(x = ID, y = scaled_mpg,
fill= factor(cyl)),stat = "identity") +
facet_grid(cyl~.)

La trama:

inserisci la descrizione dell'immagine qui

Messaggi simili:

risposte:

29 per risposta № 1

1) O di aggiungendo position = "identity" a geom_bar o, naturalmente, usando

suppressWarnings(print(ggplot(...)))

2-3) Considerando il lato tecnico - sì, puoi ignorarlo. Il ragionare per questo avviso è legato all'interpretazione che le barre sono negative altezza invece di solo valori negativi.