Here we explain how to generate a presentation/publication-quality histogram in R/R-studio. The codes for the steps explained in the video are as follows. Copy and paste them into R, run them one-by-one and try to understand what each argument is doing.
#datascience #datavisualization #visualization #ggplot2 #tidyverse #histogram #rstudio #rcoding #normal
Step 0: If you don't know how to load data into R, simulate a vector X using
X = rnorm(1e4, mean = 175, sd = 10)
Step 1: hist(X)
Step 2: hist(X, probability = T)
Step 3: hist(X, probability = T, main = "")
Step 4: hist(X, probability = T, main = "Histogram of heights")
Step 5: hist(X, probability = T, main = "Histogram of heights", xlab = "Height (cm)")
Step 6: hist(X, probability = T, main = "Histogram of heights", xlab = "Height (cm)", cex.main = 2)
Step 7: hist(X, probability = T, main = "Histogram of heights", xlab = "Height (cm)", cex.main = 2, cex.lab = 2)
Step 8: par(mar=c(5, 5, 4, 1)) # south west north east
hist(X, probability = T, main = "Histogram of heights", xlab = "Height (cm)", cex.main = 2, cex.lab = 2)
Step 9: par(mar=c(5, 5, 4, 1)) # south west north east
hist(X, probability = T, main = "Histogram of heights", xlab = "Height (cm)", cex.main = 2, cex.lab = 2, cex.axis = 2)