R Markdown

AhmedData <- read_excel("AhmedData.xlsx")
colnames(AhmedData)  # check actual column names
## [1] "Year"       "Ave_tem"    "Tot_precip"
head(AhmedData)
## # A tibble: 6 × 3
##   Year   Ave_tem Tot_precip
##   <chr>    <dbl>      <dbl>
## 1 1900/4     8.1      108. 
## 2 1900/5    13.7      144. 
## 3 1900/6    17.3       57.6
## 4 1900/7    20.5      168. 
## 5 1900/8    24.9       73.3
## 6 1900/9    19.3      286.
# Select a smaller subset for visualization
subset_data <- AhmedData[1:200, ]

Average Temperature Over Time

# Convert Year to numeric (assuming Year is in the format "1900/04")
AhmedData$Year <- as.numeric(sub("/.*", "", AhmedData$Year))  # Extract the year from the date string

# Filter data for years between 1900 and 2000 (1 to 100 years from start)
filtered_data <- AhmedData %>% filter(Year >= 1900 & Year <= 2024)

# Line plot of Average Temperature over time (1900 to 2000)
ggplot(filtered_data, aes(x = Year, y = Ave_tem)) +
  geom_line(color = "blue") +
  labs(title = "Line Plot of Average Temperature Over Time (1900-2000)",
       x = "Year", y = "Average Temperature (℃)") +
  theme_minimal()

# Line plot of Total Precipitation over time (1900 to 2000)
ggplot(filtered_data, aes(x = Year, y = Tot_precip)) +
  geom_line(color = "green") +
  labs(title = "Line Plot of Total Precipitation Over Time (1900-2000)",
       x = "Year", y = "Total Precipitation (mm)") +
  theme_minimal()

Summary of Temperature and Precipitation

summary(AhmedData[, c("Ave_tem", "Tot_precip")])
##     Ave_tem        Tot_precip   
##  Min.   :-4.40   Min.   :  1.4  
##  1st Qu.: 2.70   1st Qu.: 98.0  
##  Median :11.50   Median :133.5  
##  Mean   :11.11   Mean   :148.3  
##  3rd Qu.:19.10   3rd Qu.:183.5  
##  Max.   :30.00   Max.   :543.0

the relationship between Average Temperature and Total Precipitation

ggplot(AhmedData, aes(x = Ave_tem, y = Tot_precip)) +
  geom_point(color = "blue") +
  labs(title = "Scatter Plot of Average Temperature vs Total Precipitation",
       x = "Average Temperature (℃)", y = "Total Precipitation (mm)") +
  theme_minimal()

Average Temperature Histogram

# Histogram of Average Temperature
ggplot() +
  geom_histogram(data = AhmedData, aes(x = Ave_tem), binwidth = 1, fill = "steelblue", color = "black", alpha = 0.5) +
  geom_histogram(data = AhmedData, aes(x = Tot_precip), binwidth = 10, fill = "darkgreen", color = "black", alpha = 0.5) +
  labs(title = "Distribution of Average Temperature and Total Precipitation",
       x = "Value", y = "Frequency") +
  theme_minimal()

## Scatter Plot of Average Temperature vs Total Precipitation (Subset Data)

ggplot(AhmedData, aes(x = Ave_tem, y = Tot_precip)) +
  geom_point(color = "blue") +
  geom_smooth(method = "lm", color = "red") +
  labs(title = "Scatter Plot of Average Temperature vs Total Precipitation",
       x = "Average Temperature (℃)", y = "Total Precipitation (mm)") +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

# Aggregate by Year
aggregated_data <- AhmedData %>%
  group_by(Year) %>%
  summarise(
    Avg_Ave_tem = mean(Ave_tem, na.rm = TRUE),
    Avg_Tot_precip = mean(Tot_precip, na.rm = TRUE)
  )

# Check the first few rows to ensure it is created
head(aggregated_data)
## # A tibble: 6 × 3
##    Year Avg_Ave_tem Avg_Tot_precip
##   <dbl>       <dbl>          <dbl>
## 1  1900        14.0           169.
## 2  1901        10.7           138.
## 3  1902        10.3           154.
## 4  1903        10.7           178.
## 5  1904        10.6           163.
## 6  1905        10.4           163.

Aggregated Data by Year

ggplot(aggregated_data, aes(x = Year)) +
  geom_line(aes(y = Avg_Ave_tem), color = "blue") +
  geom_line(aes(y = Avg_Tot_precip), color = "green") +
  labs(title = "Aggregated Average Temperature and Total Precipitation Over Time",
       x = "Year", y = "Value") +
  theme_minimal()

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(AhmedData)
##       Year         Ave_tem        Tot_precip   
##  Min.   :1900   Min.   :-4.40   Min.   :  1.4  
##  1st Qu.:1931   1st Qu.: 2.70   1st Qu.: 98.0  
##  Median :1962   Median :11.50   Median :133.5  
##  Mean   :1962   Mean   :11.11   Mean   :148.3  
##  3rd Qu.:1993   3rd Qu.:19.10   3rd Qu.:183.5  
##  Max.   :2024   Max.   :30.00   Max.   :543.0
# Replace the file path with the actual Excel file path
AhmedData <- read_excel("AhmedData.xlsx")  # Use exact filename or full path if needed
head(AhmedData)
## # A tibble: 6 × 3
##   Year   Ave_tem Tot_precip
##   <chr>    <dbl>      <dbl>
## 1 1900/4     8.1      108. 
## 2 1900/5    13.7      144. 
## 3 1900/6    17.3       57.6
## 4 1900/7    20.5      168. 
## 5 1900/8    24.9       73.3
## 6 1900/9    19.3      286.

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.