With a data frame df
and a column col_name
I use the below function to generate histograms like in the figure below.
myHistogramDensity <- function(df, col_name) {
p1 <- ggplot(df, aes_string(x=col_name)) +
geom_histogram(aes(y=..density..), binwidth=1, colour="black", fill="white")
p1 <- p1 + scale_y_continuous(labels=percent)
p1 <- p1 + annotation_custom(tableGrob(myMinMaxMed(df, col_name), rows = NULL),
xmin=10, xmax=13, ymin=0.5, ymax=0.6)
return (p1)
}
This gives me a histogram like below.
How do I get the x-axis to display labels for all discrete values present in col_name
?