Joshua G. answered 09/20/24
PhD in Biostatistics with 11 Years of R Programming Experience
Rotating the x axis labels for a bar plot is straightforward when you use the R library called ggplot2. The following directions are inspired by the discussion presented at https://www.statology.org/rotate-axis-labels-ggplot2/.
#This creates the dataframe with the information you want to display in your barplot (assuming that data1 #and average already exists in your R workspace)
df = data.frame(normalized.diff = ((data1[,1] - average)/average) * 100), resorts = data1[,2])
#This loads the ggplot 2 library, which is necessary for the remaining code to run correctly
library(ggplot2)
#This constructs the bar plot with the x axis labels rotated by 45 degrees
#The values for vjust and hjust may need to be adjusted to make the rotated x axis labels
#sufficiently close to the bar plot
ggplot(data = df, aes(x = resorts, y = normalized.diff)) +
geom_bar(stats = "identity",colour = "#3CA0D0") +
theme(axis.text.x = element_text(angle=45, vjust=.5, hjust=1)) +
labs(main = "Best Lift Time to Vertical Drop Ratios of North American Resorts",
ylab = "Normalized Difference")