ho i seguenti dati semplicicome definire i colori di riempimento nell'istogramma ggplot?
data <- structure(list(status = c(9, 5, 9, 10, 11, 10, 8, 6, 6, 7, 10,
10, 7, 11, 11, 7, NA, 9, 11, 9, 10, 8, 9, 10, 7, 11, 9, 10, 9,
9, 8, 9, 11, 9, 11, 7, 8, 6, 11, 10, 9, 11, 11, 10, 11, 10, 9,
11, 7, 8, 8, 9, 4, 11, 11, 8, 7, 7, 11, 11, 11, 6, 7, 11, 6,
10, 10, 9, 10, 10, 8, 8, 10, 4, 8, 5, 8, 7), statusgruppe = c(0,
0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, NA, 0, 1, 0, 1,
0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1,
1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0,
1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0)), .Names = c("status",
"statusgruppe"), class = "data.frame", row.names = c(NA, -78L
))
da che mi piacerebbe fare un istogramma:
ggplot(data, aes(status))+
geom_histogram(aes(y=..density..),
binwidth=1, colour = "black",
fill="white")+
theme_bw()+
scale_x_continuous("Staus", breaks=c(min(data$status,na.rm=T), median(data$status, na.rm=T), max(data$status, na.rm=T)),labels=c("Low", "Middle", "High"))+
scale_y_continuous("Percent", formatter="percent")
Ora - mi piacerebbe che i bidoni di prendere colou in base al valore - ad esempio i contenitori con valore> 9 diventano grigio scuro - tutto il resto dovrebbe essere grigio chiaro.
Ho provato con fill=statusgruppe
, scale_fill_grey(breaks=9)
ecc., Ma non riesco a farlo funzionare. Qualche idea?
Grazie - Ho cambiato il legendlabel in questo modo (per i posteri) scale_fill_grey ("Nome", interruzioni = c (FALSE, VERO), etichette = c ("Questo", "Quello")). Un'altra domanda però: - è possibile fare qualcosa come ..x ..> 7, ..x ..> 9 (Se voglio tre categorie invece di solo due?) – Andreas
In tal caso, usa 'cut' . – hadley
Grazie! - se qualcun altro è interessato, ecco come l'ho fatto: fill = cut (.. x .., c (1,6,10))), binwidth = 1, color = "black", ) + scale_fill_grey ( "nome", breaks = c ("(1,6]", "(6,10]", NA), labels = c ("Low", "Midle", "High")) + – Andreas