'How to add labels in percentage format in histogram hist() in R?
I'm using the hist() command r-base to generate a histogram with freq=TRUE.
I would like the label to be shown as a percentage.
my code without label percent
df<-read.csv("http://wesleysc352.github.io/correl.csv", sep=",", header = TRUE)%>%
select(correl)
hist(unlist(df),
breaks = seq(-1,1,0.125),
ylim = c(0,200),
xaxt = "n",
freq=TRUE,
right = TRUE,
main = "Histograma Frequência das Correlações",#título
xlab="Correlação encontrada nas Área_inf", ylab="Frequência",
labels = TRUE)
axis(1, at = c(-1,-0.875,-0.75,-0.625,-0.50,-0.375,-0.25,-0.125,0,0.125,0.25,0.375,0.50,0.625,0.75,0.875,1))
abline(v=c(-0.5,0.5), col=c("red", "red"), lty=c(2,2), lwd=c(3, 3))
I tried to use this tip, but I didn't have success in my code.
df<-read.csv("http://wesleysc352.github.io/correl.csv", sep=",", header = TRUE)%>%
select(correl)
hist(unlist(df),
breaks = seq(-1,1,0.125),
ylim = c(0,200),
xaxt = "n",
freq=TRUE,
right = TRUE,
main = "Histograma Frequência das Correlações",#título
xlab="Correlação encontrada nas Área_inf", ylab="Frequência",
labels = paste0(round(hist(df, plot = FALSE)$counts/length(correl)*100, 1), "%"))
axis(1, at = c(-1,-0.875,-0.75,-0.625,-0.50,-0.375,-0.25,-0.125,0,0.125,0.25,0.375,0.50,0.625,0.75,0.875,1))
abline(v=c(-0.5,0.5), col=c("red", "red"), lty=c(2,2), lwd=c(3, 3))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

