30/01/2025library(readr)
mars_data <- read_csv("C:/Users/rbada/Downloads/Mars-weather.csv")
## Rows: 1894 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): month, atmo_opacity
## dbl (7): id, sol, ls, min_temp, max_temp, pressure, wind_speed
## date (1): terrestrial_date
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
# Summarize min and max temperature along with pressure
summary_stats <- mars_data %>%
select(min_temp, max_temp, pressure) %>%
summary()
summary_stats
## min_temp max_temp pressure
## Min. :-90.00 Min. :-35.00 Min. :727.0
## 1st Qu.:-80.00 1st Qu.:-23.00 1st Qu.:800.0
## Median :-76.00 Median :-11.00 Median :853.0
## Mean :-76.12 Mean :-12.51 Mean :841.1
## 3rd Qu.:-72.00 3rd Qu.: -3.00 3rd Qu.:883.0
## Max. :-62.00 Max. : 11.00 Max. :925.0
## NA's :27 NA's :27 NA's :27
Insight:the data shows that temperatures on Mars can drop as low as -90°C and reach a maximum of -62°C, with an average of -76°C. The atmospheric pressure ranges from 727 Pa to 925 Pa, with an average of 841 Pa. These values highlight the extremely cold and thin atmosphere on Mars, which is important to consider when planning future missions, especially for designing life support systems and protective equipment.
# Unique values for month and opacity
categorical_summary <- mars_data %>%
select(month, atmo_opacity) %>%
summarise(
Unique_Months = n_distinct(month),
Unique_Opacities = n_distinct(atmo_opacity)
)
# Counts of opacities by month
value_counts <- mars_data %>%
group_by(month, atmo_opacity) %>%
summarise(Count = n())
## `summarise()` has grouped output by 'month'. You can override using the
## `.groups` argument.
categorical_summary
## # A tibble: 1 × 2
## Unique_Months Unique_Opacities
## <int> <int>
## 1 12 2
value_counts
## # A tibble: 14 × 3
## # Groups: month [12]
## month atmo_opacity Count
## <chr> <chr> <int>
## 1 Month 1 Sunny 176
## 2 Month 10 -- 1
## 3 Month 10 Sunny 115
## 4 Month 11 -- 2
## 5 Month 11 Sunny 143
## 6 Month 12 Sunny 166
## 7 Month 2 Sunny 182
## 8 Month 3 Sunny 194
## 9 Month 4 Sunny 194
## 10 Month 5 Sunny 149
## 11 Month 6 Sunny 153
## 12 Month 7 Sunny 142
## 13 Month 8 Sunny 141
## 14 Month 9 Sunny 136
Insight:the categorical summary shows that the data covers 12 months and includes 2 opacity categories: “Sunny” and “–”. Most months have high counts of “Sunny” conditions, while Month 10 and 11 show “–”, indicating possible data gaps. This is important for identifying missing data and understanding seasonal trends in atmospheric conditions.
# Load necessary libraries
library(dplyr)
# Combined summary for categorical columns
combined_categorical_summary <- mars_data %>%
group_by(month, atmo_opacity) %>%
summarise(
Count = n(),
) %>%
arrange(month)
## `summarise()` has grouped output by 'month'. You can override using the
## `.groups` argument.
# View the combined summary
combined_categorical_summary
## # A tibble: 14 × 3
## # Groups: month [12]
## month atmo_opacity Count
## <chr> <chr> <int>
## 1 Month 1 Sunny 176
## 2 Month 10 -- 1
## 3 Month 10 Sunny 115
## 4 Month 11 -- 2
## 5 Month 11 Sunny 143
## 6 Month 12 Sunny 166
## 7 Month 2 Sunny 182
## 8 Month 3 Sunny 194
## 9 Month 4 Sunny 194
## 10 Month 5 Sunny 149
## 11 Month 6 Sunny 153
## 12 Month 7 Sunny 142
## 13 Month 8 Sunny 141
## 14 Month 9 Sunny 136
Insight:the combined summary shows the frequency of each month and opacity combination. Most months have high counts of “Sunny” conditions, indicating clear skies are common throughout the year. However, Month 10 and 11 have “–” (missing data) with very few occurrences, suggesting possible data collection gaps or unmeasured conditions during those months. This combined summary helps spot missing data, analyze seasonal patterns, and guide further investigation into potential causes.
A set of at least 3 novel questions to investigate informed by the following:.
1.Does atmospheric opacity affect temperature on Mars?
2.Are there specific months that consistently record lower temperatures?
3.Is there a relationship between atmospheric pressure and temperature trends?
1.id (Integer) unique identifier for each observation, ensuring each row can be tracked and distinguished for analysis purposes.
2.terrestrial_date (Date) Refers to the Earth-based date corresponding to the Martian weather data, enabling chronological analysis and linking Mars observations to Earth’s timeline.
3.sol (Integer) Tracks the Martian solar day (count of days since the mission began) and enables the analysis of trends or changes in weather.
4.ls (Numeric)Represents the solar longitude (0°–360°), which corresponds to Mars’s position in its orbit and helps analyze seasonal changes affecting weather patterns.
5.month (Categorical) Specifies the Martian month (from Month 1 to Month 12), allowing seasonal trends and variations in Martian weather to be studied throughout the year.
6.min_temp (Numeric) Represents the minimum daily temperature on Mars (°C) and helps analyze the coldest weather conditions to understand extreme environments.
7.max_temp (Numeric) Indicates the maximum daily temperature on Mars (°C), providing insights into the hottest conditions and daily temperature ranges.
8.pressure (Numeric) Measures the atmospheric pressure on Mars (Pa), allowing for the study of stability and variability in Martian atmospheric conditions.
9.wind_speed(Numeric) Records the wind speed on Mars,which provides valuable information about wind dynamics and weather patterns.
10.atmo_opacity(Categorical) Describes the clarity of the Martian atmosphere (e.g.,Sunny), providing insights into atmospheric conditions such as clear skies or dusty weather.
This data set contains weather observations from Mars, collected over a specific period. It includes both numerical and categorical data, such as temperature, atmospheric pressure, and seasonal attributes, offering insights into the Martian climate. The data was likely obtained from Mars weather missions, such as NASA’s Curiosity rover or similar projects, and serves as a valuable resource for studying Martian environmental conditions.
The goal of this project is to analyze the Mars weather data set to better understand the Martian climate. This includes studying temperature patterns, atmospheric pressure, and seasonal changes across Martian months. The project aims to identify trends, explore relationships between variables like temperature and pressure, and gain insights into how Martian weather behaves over time. These findings can provide valuable context for future Mars missions and research.
#We can use an aggregation function (mean) to calculate the average temperature for each opacity category and compare “Sunny” versus “–”.
# Calculate average min and max temperatures by atmospheric opacity
opacity_temp_summary <- mars_data %>%
group_by(atmo_opacity) %>%
summarise(
avg_min_temp = mean(min_temp, na.rm = TRUE),
avg_max_temp = mean(max_temp, na.rm = TRUE),
count = n()
)
print(opacity_temp_summary)
## # A tibble: 2 × 4
## atmo_opacity avg_min_temp avg_max_temp count
## <chr> <dbl> <dbl> <int>
## 1 -- NaN NaN 3
## 2 Sunny -76.1 -12.5 1891
We can calculate the correlation between atmospheric pressure and temperature.
# Calculate correlation between pressure and temperature
correlation_pressure_temp <- cor(mars_data$pressure, mars_data$min_temp, use = "complete.obs")
print(paste("Correlation between pressure and minimum temperature:", correlation_pressure_temp))
## [1] "Correlation between pressure and minimum temperature: 0.153240494690897"
To visualize how temperatures are distributed and detect any clustering or extreme values.
library(ggplot2)
# Histogram for min and max temperatures
ggplot(mars_data) +
geom_histogram(aes(x = min_temp, fill = "Min Temperature"), bins = 30, alpha = 0.7, color = "black") +
geom_histogram(aes(x = max_temp, fill = "Max Temperature"), bins = 30, alpha = 0.5, color = "black") +
scale_fill_manual(values = c("skyblue", "orange")) +
labs(title = "Distribution of Minimum and Maximum Temperatures on Mars",
x = "Temperature (°C)", y = "Frequency") +
theme_minimal()
## Warning: Removed 27 rows containing non-finite outside the scale range (`stat_bin()`).
## Removed 27 rows containing non-finite outside the scale range (`stat_bin()`).
Insights:Distribution of Temperatures: The histogram shows that minimum temperatures cluster around -80°C, while maximum temperatures vary more widely. This highlights the consistently cold Martian environment with occasional warmer days.
To identify if there is a correlation between atmospheric pressure and minimum temperatures.
# Scatter plot for pressure and minimum temperature
ggplot(mars_data, aes(x = pressure, y = min_temp, color = atmo_opacity)) +
geom_point(alpha = 0.7) +
geom_smooth(method = "lm", color = "darkred", se = FALSE) +
labs(title = "Relationship Between Atmospheric Pressure and Minimum Temperature",
x = "Atmospheric Pressure (Pa)", y = "Minimum Temperature (°C)", color = "Opacity") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 27 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 27 rows containing missing values or values outside the scale range
## (`geom_point()`).
The scatter plot illustrates the relationship between atmospheric pressure and minimum temperature, with points color-coded by atmospheric opacity (‘Sunny’ or ‘–’). The trend line shows a slightly positive correlation, suggesting that higher pressure is generally associated with slightly higher minimum temperatures. Although the overall correlation is weak, it offers valuable insight into how pressure fluctuations may impact surface temperature on Mars.”
"--") Coincide with Extreme
Temperatures or Low Pressure?Here’s how you can visualize this using boxplots to compare the distributions of minimum temperature and atmospheric pressure under “Sunny” and “–” opacity.
library(ggplot2)
# Box plot for minimum temperature
ggplot(mars_data, aes(x = atmo_opacity, y = min_temp, fill = atmo_opacity)) +
geom_boxplot(alpha = 0.7, outlier.color = "red", outlier.size = 2) +
labs(
title = "Distribution of Minimum Temperature by Atmospheric Opacity",
x = "Opacity",
y = "Minimum Temperature (°C)"
) +
scale_fill_manual(values = c("Sunny" = "skyblue", "--" = "red")) +
theme_minimal()
## Warning: Removed 27 rows containing non-finite outside the scale range
## (`stat_boxplot()`).
ggplot(mars_data, aes(x = atmo_opacity, y = pressure, fill = atmo_opacity)) +
geom_boxplot(alpha = 0.7, outlier.color = "red", outlier.size = 2) +
labs(
title = "Distribution of Atmospheric Pressure by Atmospheric Opacity",
x = "Opacity",
y = "Atmospheric Pressure (Pa)"
) +
scale_fill_manual(values = c("Sunny" = "skyblue", "--" = "red")) +
theme_minimal()
## Warning: Removed 27 rows containing non-finite outside the scale range
## (`stat_boxplot()`).
# Check the number of observations for "--" opacity
missing_opacity_summary <- mars_data %>%
filter(atmo_opacity == "--") %>%
summarise(
min_temp_missing = sum(is.na(min_temp)),
pressure_missing = sum(is.na(pressure)),
total_rows = n()
)
print(missing_opacity_summary)
## # A tibble: 1 × 3
## min_temp_missing pressure_missing total_rows
## <int> <int> <int>
## 1 3 3 3
The box plots visualize the distribution of atmospheric pressure and minimum temperature under “Sunny” opacity conditions. However, “–” opacity is not displayed due to missing values. Upon investigation, we identified 3 rows with “–” opacity, all of which have missing values for temperature and pressure. This prevents them from being included in the plots. Further investigation is necessary to determine the cause of these missing values and whether they impact the analysis.
We’ll visualize how temperatures vary across months to see if there’s a seasonal trend.
library(ggplot2); library(dplyr)
monthly_temp_trends <- mars_data %>%
mutate(month = as.numeric(sub("Month ", "", month))) %>% group_by(month) %>% summarize(avg_min_temp = mean(min_temp, na.rm = TRUE), avg_max_temp = mean(max_temp, na.rm = TRUE))
ggplot(monthly_temp_trends, aes(x = month)) +
geom_line(aes(y = avg_min_temp, color = "Min Temp"), linewidth = 1) +geom_line(aes(y = avg_max_temp, color = "Max Temp"), linewidth = 1) +
labs(title = "Monthly Temperature Trends on Mars", x = "Month", y = "Average Temperature (°C)", color = "Temperature Type") +
scale_x_continuous(breaks = 1:12) +scale_color_manual(values = c("Min Temp" = "blue", "Max Temp" = "orange")) +theme_minimal()
The plot shows how Mars temperatures change across the year. The blue line represents the average minimum temperatures (around -80°C), while the orange line shows the maximum temperatures (rising to around 0°C during warmer months). Coldest months: Around Month 3 and 4. Warmest months: Around Month 7 and 8. This seasonal pattern is important for understanding Mars’ climate and planning missions.