Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Data Science
  • Data Science Projects
  • Data Analysis
  • Data Visualization
  • Machine Learning
  • ML Projects
  • Deep Learning
  • NLP
  • Computer Vision
  • Artificial Intelligence
Open In App
Next Article:
Weather Data Visualization using R
Next article icon

Weather Data Visualization using R

Last Updated : 24 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Visualizing weather data is essential for understanding trends, patterns, and anomalies in meteorological information. R, with its robust packages for data manipulation and visualization, offers powerful tools to create insightful weather data visualizations. This article will guide you through the process of visualizing weather data in R, covering data acquisition, preprocessing, and creating various types of visualizations.

Objectives and Goals

The primary objective of this article is to explore weather data visualization techniques and develop a forecasting model using R Programming Language. By exploring a dataset containing historical weather information, we try to demonstrate the power of data visualization in understanding trends and patterns, as well as the effectiveness of forecasting models in predicting future weather conditions.

Dataset Link: Weather History

The weather dataset has various columns such as:

  1. Formatted Date
  2. Summary
  3. Precip Type
  4. Temperature (C)
  5. Apparent Temperature (C)
  6. Humidity
  7. Wind Speed (km/h)
  8. Wind Bearing (degrees)
  9. Visibility (km)
  10. Loud Cover
  11. Pressure (millibars)
  12. Daily Summary

We're using the weather dataset for our analysis and predictions. By this, we can make sure that our results are reliable and stay the same without adding any extra data from outside sources.

Step 1: Load Required Libraries and Dataset

Loads the necessary libraries ggplot2 and forecast into the R environment. These libraries contain functions and tools that we'll use for data visualization and forecasting, respectively. Here, we read the weather dataset from the specified file path using the read.csv() function.

R
# Load necessary libraries library(readr)     # For reading CSV files library(dplyr)     # For data manipulation library(ggplot2)   # For data visualization library(forecast)  # For forecasting  df<-read.csv('C:\Users\GFG19565\Downloads\daily_weather_2020.csv') 

Step 2: Display the Structure of the Dataset

It displays the structure of the weather_data dataset, showing information about its variables, data types, and other properties. It helps us to understand the structure of the dataset we're working with.

R
str(df) 

Output:

'data.frame':   96453 obs. of  12 variables:
$ Formatted.Date : chr "2006-04-01 00:00:00.000 +0200" "2006-04-01 01:00:00.000 +0200" "
$ Summary : chr "Partly Cloudy" "Partly Cloudy" "Mostly Cloudy" "Partly Cloudy" ...
$ Precip.Type : chr "rain" "rain" "rain" "rain" ...
$ Temperature..C. : num 9.47 9.36 9.38 8.29 8.76 ...
$ Apparent.Temperature..C.: num 7.39 7.23 9.38 5.94 6.98 ...
$ Humidity : num 0.89 0.86 0.89 0.83 0.83 0.85 0.95 0.89 0.82 0.72 ...
$ Wind.Speed..km.h. : num 14.12 14.26 3.93 14.1 11.04 ...
$ Wind.Bearing..degrees. : num 251 259 204 269 259 258 259 260 259 279 ...
$ Visibility..km. : num 15.8 15.8 15 15.8 15.8 ...
$ Loud.Cover : num 0 0 0 0 0 0 0 0 0 0 ...
$ Pressure..millibars. : num 1015 1016 1016 1016 1017 ...
$ Daily.Summary : chr "Partly cloudy throughout the day." "Partly cloudy throughout the day.

Step 3: Visualization of Weather Data

Now we will plot the visualization of our Weather Data to get some valid pieces of information.

Histogram of Precipitation Intensity

A histogram of precipitation intensity reveals the distribution of precipitation events, highlighting the most common precipitation intensities and indicating the range of values.

R
ggplot(df, aes(x = precipIntensity)) +   geom_histogram(binwidth = 0.01, fill = "lightblue", color = "black") +   labs(title = "Distribution of Precipitation Intensity",        x = "Precipitation Intensity (mm/hr)",        y = "Frequency") +   theme_minimal() 

Output:


gh
Weather Data Visualization


Scatter Plot of Wind Speed vs. Temperature

A scatter plot shows the relationship between wind speed and high temperature. This can help identify any correlations between wind conditions and temperature changes.

R
ggplot(df, aes(x = windSpeed, y = temperatureHigh)) +   geom_point(alpha = 0.5, color = "purple") +   labs(title = "Wind Speed vs. High Temperature",        x = "Wind Speed (km/h)",        y = "High Temperature (°C)") +   theme_minimal() 

Output:


gh
Weather Data Visualization


Bar Plot of Precipitation Types

A bar plot displays the frequency of different types of precipitation (e.g., rain, snow), providing an overview of the distribution of precipitation types within the dataset.

R
ggplot(df, aes(x = precipType)) +   geom_bar(fill = "pink", color = "darkblue") +   labs(title = "Frequency of Precipitation Types",        x = "Precipitation Type",        y = "Frequency") +   theme_minimal() 

Output:


gh
Weather Data Visualization


Histogram with Density Plot

We can plot the distribution of temperatures across the dataset, with the histogram showing the frequency of different temperature ranges.

R
# Create a histogram with density plot ggplot(weather_data, aes(x = `Temperature (C)`)) +   geom_histogram(aes(y = ..density..), bins = 30, fill = "Red", color = "black",                   alpha = 0.5) +  # Histogram with filled bars   geom_density(fill = "green", alpha = 0.5) +  # Density plot with filled area   labs(title = "Histogram with Density Plot",  # Title of the plot        x = "Temperature (°C)",  # X-axis label        y = "Density") +  # Y-axis label   theme_minimal()  # Using minimal theme for aesthetics 

Output:


Weather Data Visualization


The spread of the histogram and density plot illustrates the variability or range of temperatures present in the dataset. A wider spread indicates a greater variability in temperature readings, while a narrower spread suggests more consistency in temperature values.

Conclusion

Visualizing weather data in R allows you to uncover trends, patterns, and anomalies in meteorological data. By leveraging packages like ggplot2, Plotly, and dygraphs, you can create both static and interactive visualizations that provide valuable insights. Whether you're analyzing temperature trends, humidity levels, or wind speeds, R offers the tools you need to effectively visualize and interpret weather data.


Next Article
Weather Data Visualization using R

M

manojjai07nu
Improve
Article Tags :
  • Blogathon
  • R Machine Learning
  • AI-ML-DS
  • R Projects
  • AI-ML-DS With R
  • Data Science Blogathon 2024

Similar Reads

    Data Visualization with Highcharter in R
    Highcharter is an R package that provides an interface to the Highcharts JavaScript library, enabling the creation of interactive and customizable charts. It supports a variety of chart types, such as line, bar and scatter charts and offers extensive customization options for appearance and behavior
    5 min read
    Multivariate Data Visualization with R
    A method for visualizing data with numerous variables is called multivariate data visualization with R. In this method, graphs and charts are made to show how the various factors relate to one another. The programming language R, which is frequently used for data visualization, provides a number of
    5 min read
    Master Data Visualization With ggplot2
    In this article, we are going to see the master data visualization with ggplot2 in R Programming Language. Generally, data visualization is the pictorial representation of a dataset in a visual format like charts, plots, etc.  These are the important graphs in data visualization with ggplot2, Bar Ch
    8 min read
    Weather and Climate Change Trends Visualization in R
    Weather and climate change are critical issues that affect weather patterns worldwide. Visualizing climate data helps to understand these changes and their impacts. Here we show how to visualize climate change trends using a weather dataset in R Programming Language. The dataset contains daily weath
    6 min read
    Getting started with Data Visualization in R
    Data visualization is the practice of representing data through visual elements like graphs, charts, and maps. It helps in understanding large datasets more easily, making it possible to identify patterns and trends that support better decision-making. R is a language designed for statistical analys
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences