Forse la risposta è solo essere avvertiti. Sto attmepting di usare una variabile in scala e centrata per vedere come le osservazioni differiscono dal valore medio. Questa trama è una pratica comune. Ma quando lo faccio ricevo un avviso da ggplot2
.avviso ggplot2: impilamento non ben definito quando ymin! = 0
Warning messages:
1: Stacking not well defined when ymin != 0
Mi piace avere ggplot2 e il resto del mondo felice e nessun avviso che viene a modo mio. Ho cercato di eliminare l'avviso nei seguenti modi e ho cercato SO (vedi i collegamenti in basso per alcune domande più promettenti) per domande correlate. Ancora il mio amico ggplot2 mi sta avvisando.
Question (s):
- Come posso fare l'avvertimento andare via?
- Posso ignorare l'avviso?
- C'è qualcosa di sbagliato in questa pratica?
tentativi Code:
## 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:
Interventi simili:
- set length of `geom_hline` in `geom_bar` plot
- ggplot2 - stacking not well defined when ymin !=0
- ggplot2 and a Stacked Bar Chart with Negative Values
Sì. L'avviso deve essere ignorato in questo caso. È solo lì per mettere in guardia le persone che potrebbero commettere la strategia di menzogne con statistiche usando un riferimento diverso da zero per i diagrammi a barre. Diamine, non ti stai nemmeno impilando dopo aver aggiunto le faccette. –