Circular Bar Plot: Average U.S. Wave Heights

Shota Hasui

2023-05-16

For this project, I created a circular bar chart that displays the average wave heights for a sample of U.S. surf locations. The height data are randomly generated via R.

Code can be found below.

library(tidyverse)
set.seed(42)  # for reproducibility

# fictional dataset for wave heights in U.S. surf locations
surf_data <- tibble(
  location = factor(rep(c("Pipeline", 
                          "Mavericks", 
                          "Trestles", 
                          "Rincon", 
                          "The Wedge", 
                          "Malibu", 
                          "Jaws (Peahi)", 
                          "Huntington Beach", 
                          "Banzai Pipeline", 
                          "Blacks Beach", 
                          "Sebastian Inlet", 
                          "Ocean Beach", 
                          "Cape Hatteras", 
                          "Montauk", 
                          "Ruggles"), 
                        each = 100)),
  wave_height = rnorm(1500, mean = runif(15, 5, 10), sd = runif(15, 5, 10)) # larger standard deviation
)

# data manipulation: calculate average wave height for each location
surf_summary <- surf_data %>%
  group_by(location) %>%
  summarise(avg_wave_height = mean(wave_height))

# color choice
blue_colors <- colorRampPalette(colors = c("lightblue", "blue"))(15)

# data visualisation
ggplot(surf_summary) +
  geom_col(aes(x = location, y = avg_wave_height, fill = location), 
           show.legend = FALSE,
           alpha = .9) +
  geom_text(aes(x = location, y = avg_wave_height/2, label = round(avg_wave_height, 1)), 
            vjust = 0.5, size = 4, color = "white", fontface = "bold") +  # Bold text
  scale_fill_manual(values = blue_colors) +
  coord_polar() +
  labs(title = "Average Wave Heights in U.S. Surf Locations",
       x = "",  # Removes x-axis label
       y = "Average Wave Height (ft)") +
  theme_minimal() +
  theme(
    legend.position = "none",
    axis.title.y = element_blank(),
    axis.text.y = element_blank(),
    panel.grid = element_blank(),
    text = element_text(color = "gray12", face = "bold"),  # Bold text
    axis.text.x = element_text(angle = 45, hjust = 1, face = "bold"),  # Bold text
    plot.title = element_text(hjust = 0.5, face = "bold")  # Bold title
  )