Comment puis-je mettre en évidence le bac d'une observation dans un histogramme en R

StackOverflow https://stackoverflow.com/questions/2127926

  •  22-09-2019
  •  | 
  •  

Question

Je veux créer un histogramme à partir d'un certain nombre d'observations (c.-à-d <- c (1,2.1,3.4,4.5)) puis mettez en surbrillance le bac qu'une observation particulière tombe, de sorte que j'ai une sortie qui ressemble comme ça: text alt

comment dois-je faire cela en R?

Était-ce utile?

La solution

L'expansion sur la réponse de dangerstat, voici une petite fonction qui trouvera automatiquement le bac contient la valeur que vous souhaitez mettre en évidence:

highlight <- function(x, value, col.value, col=NA, ...){
   hst <- hist(x, ...)
   idx <- findInterval(value, hst$breaks)
   cols <- rep(col, length(hst$counts))
   cols[idx] <- col.value
   hist(x, col=cols, ...)
}

x <- rnorm(100)
highlight(x, 1.2, "red")

mettra en évidence le bac avec 1.2 en rouge.

Autres conseils

x = rnorm(100)
hist(x,br=10,col=c(rep(0,9),1))

Il est clair que cette colorera la dernière colonne afin tweak le col = bit pour vos besoins

Merci

dangerstat

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top