library(dplyr)
# Compute average temperature per year
df_avg <- df %>%
rowwise() %>%
mutate(Average_Temperature = mean(c_across(-Year), na.rm = TRUE)) # Exclude "Year" column
# Create the bar chart
ggplot(df_avg, aes(x = Year, y = Average_Temperature, fill = as.factor(Year))) +
geom_bar(stat = "identity", show.legend = FALSE) + # Bar chart
scale_fill_viridis_d() + # Use a color palette
labs(title = "Average Yearly Temperature",
x = "Year",
y = "Average Temperature (°C)") +
theme_minimal()
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter