df <- read.csv("DataCurahHujan.csv", sep=";")
colnames(df)[1] <- "CurahHujan"
colnames(df)[2] <- "DebitSungai"
df$CurahHujan <- as.numeric(gsub(",", ".", df$CurahHujan))
df$DebitSungai <- as.numeric(gsub(",", ".", df$DebitSungai))
head(df)
## CurahHujan DebitSungai Suhu_C Kelembapan.udara.... Kecepatan.angin..m.s.
## 1 76.7 9.37 26,9 84 2,1
## 2 53.8 8.86 25,1 71 1,7
## 3 34.5 8.52 28,3 77 3,1
## 4 13.1 6.06 22,2 83 2,7
## 5 48.4 7.25 25 87 3,2
## 6 65.4 7.67 23,7 75 3,1
## Tinggi.muka.air..m. Bulan Musim
## 1 1,17 8 Musim Kemarau
## 2 1,07 11 Musim Hujan
## 3 1,16 6 Musim Kemarau
## 4 0,94 7 Musim Kemarau
## 5 1,06 1 Musim Hujan
## 6 0,93 4 Pancaroba 1
names(df)
## [1] "CurahHujan" "DebitSungai" "Suhu_C"
## [4] "Kelembapan.udara...." "Kecepatan.angin..m.s." "Tinggi.muka.air..m."
## [7] "Bulan" "Musim"
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.5.2
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.5.2
##
## 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
ggplot(df, aes(x = CurahHujan)) +
geom_histogram(bins = 20, fill = "purple") + # atau fill = "#800080"
theme_minimal() +
labs(
title = "Distribusi Curah Hujan",
x = "Curah Hujan (mm)",
y = "Frekuensi"
)
## Warning: Removed 1 row containing non-finite outside the scale range
## (`stat_bin()`).

ggplot(df, aes(x = CurahHujan, y = DebitSungai)) +
geom_point(color = "red") +
geom_smooth(method = "lm", se = FALSE, color = "black") +
theme_minimal() +
labs(
title = "Hubungan Curah Hujan dan Debit Air",
x = "Curah Hujan (mm)",
y = "Debit Sungai (m3/detik)"
)
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 1 row containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_point()`).
