I am trying to create some histograms with ggplot2. It is showing deviations from 0 and for the first variable it works fine as you can see in figure 1.
Figure 1:
But with the second one, there are a some extreme outliers that stretches the x-axis, as can be seen in figure 2, which is a problem
Figure 2:
Therefore, I would like to add a "greater than 5"-bin that includes all values greater than 5 (and vice versa for negative values).
I found this solution, which is exactly what I need, but I cannot figure out how to apply it: https://edwinth.github.io/blog/outlier-bin/
My code:
library(ggplot2)
require(reshape2)
#Figure 1
ggplot(data = data, aes(x = data$V1*100)) +
geom_histogram(color="white", fill='#1E206B') +
geom_vline(xintercept = 0, color="black", linetype="dashed", size=1) +
labs(x = "Percentage change", y = "Counts") +
#xlim(-max(abs(data$V1))*100,max(abs(data$V1))*100) +
theme_bw()
#Figure 2
ggplot(data = data, aes(x = data$V2*100)) +
geom_histogram(color="white", fill='#1E206B') +
geom_vline(xintercept = 0, color="black", linetype="dashed", size=1) +
labs(x = "Percantage change", y = "Counts") +
#xlim(-max(abs(data$V2))*100,max(abs(data$V2))*100) +
theme_bw()