#memuat library yang dibutuhkan
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(gridExtra)
##
## Attaching package: 'gridExtra'
##
## The following object is masked from 'package:dplyr':
##
## combine
library(readxl)
knitr::opts_chunk$set(echo = TRUE)
# Membaca dan menampilkan data
CAD_alizadeh <- read_excel("CAD alizadeh.xls")
View(CAD_alizadeh)
# 1. Age vs Length
plot1 <- ggplot(CAD_alizadeh, aes(x=Age, y=Length)) +
geom_point(color="#FF6B6B", size=2) +
geom_smooth(method=lm, color="#4ECDC4") +
labs(title="Age vs Length", x="Age", y="Length") +
theme_minimal()
# 2. Age vs Weight
plot2 <- ggplot(CAD_alizadeh, aes(x=Age, y=Weight)) +
geom_point(color="#45B7D1", size=2) +
geom_smooth(method=lm, color="#96CEB4") +
labs(title="Age vs Weight", x="Age", y="Weight") +
theme_minimal()
# 3. Age vs PR
plot3 <- ggplot(CAD_alizadeh, aes(x=Age, y=PR)) +
geom_point(color="#D65076", size=2) +
geom_smooth(method=lm, color="#EEB868") +
labs(title="Age vs PR", x="Age", y="PR") +
theme_minimal()
#menampilkan scatterplot
grid.arrange(plot1, plot2, plot3, ncol=2)
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'

#hitung korelasi
cor_age_length <- cor(CAD_alizadeh$Age, CAD_alizadeh$Length)
cor_age_weight <- cor(CAD_alizadeh$Age, CAD_alizadeh$Weight)
cor_age_pr <- cor(CAD_alizadeh$Age, CAD_alizadeh$PR)
#mencetak korelasi
cat("Correlations:\n", "age-length:", round(cor_age_length, 3), "\n", "age-weight:", round(cor_age_weight, 3), "\n", "age-pr:", round(cor_age_pr, 3))
## Correlations:
## age-length: -0.164
## age-weight: -0.265
## age-pr: 0.024