Visualize Distribution with Mean and Standard Deviation Highlights
Source:R/coloured_histogram_sd.R
coloured_histogram_sd.Rd
This function creates a histogram for a specified column in a dataframe,
highlighting the mean and one standard deviation above and below the mean.
It draws vertical lines for the mean (in black) and for plus/minus one standard
deviation (in blue and gold, respectively), with arrows from the mean to each
standard deviation marker. The title of the plot includes the capitalized column name,
achieved using tools::toTitleCase()
.
Value
A ggplot object representing the histogram with highlights for the mean and standard deviations. The plot can be printed or modified further.
Examples
if (FALSE) { # \dontrun{
# Assuming `df_nz` is a dataframe with a numeric column 'forgiveness'
# and a factor or integer column 'wave' for subsetting:
df_19 <- dplyr::filter(df_nz, wave == 2019)
graph_density_of_exposure <- coloured_histogram_sd(
df = df_19,
col_name = "forgiveness",
binwidth = 0.5 # Adjust binwidth as needed
)
} # }
print(graph_density_of_exposure)
#> Error: object 'graph_density_of_exposure' not found