library(ggplot2)
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
## ✔ lubridate 1.9.3 ✔ tibble 3.2.1
## ✔ purrr 1.0.2 ✔ tidyr 1.3.1
## ── 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("ggplot2")
library("sf")
## Linking to GEOS 3.11.2, GDAL 3.8.2, PROJ 9.3.1; sf_use_s2() is TRUE
library("rnaturalearth")
library("rnaturalearthdata")
##
## Attaching package: 'rnaturalearthdata'
##
## The following object is masked from 'package:rnaturalearth':
##
## countries110
library(sf)
library(ggspatial)
library(dplyr)
library(reshape2)
##
## Attaching package: 'reshape2'
##
## The following object is masked from 'package:tidyr':
##
## smiths
library(ggcorrplot)
library(ggforce)
library(readxl)
library(gridExtra)
##
## Attaching package: 'gridExtra'
##
## The following object is masked from 'package:dplyr':
##
## combine
library(plotly)
##
## Attaching package: 'plotly'
##
## The following object is masked from 'package:ggplot2':
##
## last_plot
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following object is masked from 'package:graphics':
##
## layout
data <- read_excel("C:/Users/TUBAGUS/Downloads/anreg.xlsx")
data[] <- lapply(data, as.numeric)
## Warning in lapply(data, as.numeric): NAs introduced by coercion
data <- subset(data, select = -c(Provinsi))
data
## # A tibble: 34 × 9
## Y X1 X2 X3 X4 X5 X6 X7 X8
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 0.79 72.8 5407900 807000 9.44 38900 9963 4424. 6.07
## 2 1.33 72.7 15115200 1268000 9.71 62922 10848 22789. 5.82
## 3 3.45 73.3 5640600 335000 9.18 50264 11130 2560. 6.22
## 4 2.2 73.5 6614400 485000 8.22 151259 11158 43062 4.38
## 5 1.59 72.1 2179800 279000 8.68 76164 10871 8883. 4.64
## 6 1.1 70.9 3631100 1045000 8.37 68237 11109 23526 4.68
## 7 1.85 72.2 8657000 297000 8.91 43757 10840 6957. 3.49
## 8 1.52 70.4 1494600 1002000 8.18 44984 10336 5809. 4.42
## 9 2.22 72.2 2060100 67000 8.11 63872 13358 6309 4.47
## 10 4.75 76.5 9176600 152000 10.4 145579 14469 4817. 8.12
## # ℹ 24 more rows
datacorr <- select_if(data, is.numeric)
str(datacorr)
## tibble [34 × 9] (S3: tbl_df/tbl/data.frame)
## $ Y : num [1:34] 0.79 1.33 3.45 2.2 1.59 1.1 1.85 1.52 2.22 4.75 ...
## $ X1: num [1:34] 72.8 72.7 73.3 73.5 72.1 ...
## $ X2: num [1:34] 5407900 15115200 5640600 6614400 2179800 ...
## $ X3: num [1:34] 807000 1268000 335000 485000 279000 ...
## $ X4: num [1:34] 9.44 9.71 9.18 8.22 8.68 ...
## $ X5: num [1:34] 38900 62922 50264 151259 76164 ...
## $ X6: num [1:34] 9963 10848 11130 11158 10871 ...
## $ X7: num [1:34] 4424 22789 2560 43062 8883 ...
## $ X8: num [1:34] 6.07 5.82 6.22 4.38 4.64 ...
data2 <- read_csv("C:/Users/TUBAGUS/Downloads/AMC (1).csv")
## Rows: 501 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (6): Open, High, Low, Close, Adj Close, Volume
## date (1): 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.
data2
## # A tibble: 501 × 7
## Date Open High Low Close `Adj Close` Volume
## <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2022-05-16 119 127. 115 117. 117. 4096000
## 2 2022-05-17 121. 129. 118. 129 129 3818350
## 3 2022-05-18 127. 142. 125. 128. 128. 5372940
## 4 2022-05-19 128. 135 127. 131. 131. 5044360
## 5 2022-05-20 132. 134. 114. 120. 120. 4138790
## 6 2022-05-23 120. 120. 114. 116. 116. 2485440
## 7 2022-05-24 113. 114. 103 104. 104. 3768930
## 8 2022-05-25 105. 119. 104 119. 119. 5362800
## 9 2022-05-26 118. 129. 116. 122. 122. 7100240
## 10 2022-05-27 126. 145. 124 144. 144. 8990600
## # ℹ 491 more rows
str(data2)
## spc_tbl_ [501 × 7] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ Date : Date[1:501], format: "2022-05-16" "2022-05-17" ...
## $ Open : num [1:501] 119 121 127 128 132 ...
## $ High : num [1:501] 127 129 142 135 134 ...
## $ Low : num [1:501] 115 118 125 127 114 ...
## $ Close : num [1:501] 117 129 128 131 120 ...
## $ Adj Close: num [1:501] 117 129 128 131 120 ...
## $ Volume : num [1:501] 4096000 3818350 5372940 5044360 4138790 ...
## - attr(*, "spec")=
## .. cols(
## .. Date = col_date(format = ""),
## .. Open = col_double(),
## .. High = col_double(),
## .. Low = col_double(),
## .. Close = col_double(),
## .. `Adj Close` = col_double(),
## .. Volume = col_double()
## .. )
## - attr(*, "problems")=<externalptr>
plot_X1 <- ggplot(data, aes(x = `X1`, y = `Y`)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(x = "IPM", y = "Migrasi")
plot_X2 <- ggplot(data, aes(x = `X2`, y = `Y`)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(x = "Jumlah Penduduk", y = "Migrasi")
plot_X3 <- ggplot(data, aes(x = `X3`, y = `Y`)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(x = "Jumlah Penduduk Miskin", y = "Migrasi")
plot_X4 <- ggplot(data, aes(x = `X4`, y = `Y`)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(x = "Rata-rata lama sekolah", y = "Migrasi")
plot_X5 <- ggplot(data, aes(x = `X5`, y = `Y`)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(x = "PDRB", y = "Migrasi")
plot_X6 <- ggplot(data, aes(x = `X6`, y = `Y`)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(x = "Pengeluaran", y = "Migrasi")
plot_X7 <- ggplot(data, aes(x = `X7`, y = `Y`)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(x = "Investasi", y = "Migrasi")
plot_X8 <- ggplot(data, aes(x = `X8`, y = `Y`)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(x = "Tingkat pengangguran", y = "Migrasi")
plot_X9 <- ggplot(data, aes(x = `X5`, y = `Y`)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(x = "indeks politik", y = "Migrasi")
# Menggabungkan scatter plot ke dalam satu layout
grid.arrange(plot_X1, plot_X2, plot_X3, plot_X4, plot_X5, plot_X6, plot_X7, plot_X8, plot_X9, nrow = 2)
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
Berdasarkan gambar di atas bahwa IPM, Jumlah Penduduk, Rata-rata lama
sekolah, PDRB, Pengeluaran, Tingkat Pengangguran, dan Indeks politik
menunjukkan hubungan linear positif yang dimana semakin tinggi IPM,
Jumlah Penduduk, Rata-rata lama sekolah, PDRB, Pengeluaran, Tingkat
Pengangguran, dan Indeks politik maka migrasi cenderung meningkat.
Sebaliknya, Jumlah Penduduk Miskin dan Investasi menunjukkan linear
negatif yang menandakan bahwa semakin sedikit Jumlah Penduduk Miskin dan
Investasi maka migrasi cenderung menurun
data_melt <- cor(datacorr[sapply(datacorr,is.numeric)])
data_melt <- melt(data_melt)
ggplot(data_melt, aes(x = Var1, y = Var2, fill = value)) +
geom_tile() +
labs(title = "Correlation Heatmap",
x = " ",
y = " ")
ggplot(data_melt, aes(Var1, Var2, fill = value)) +
geom_tile(color = "white") +
scale_fill_gradient2(low = "blue", mid = "white", high = "red", midpoint = 0, limits = c(-1,1), name="Korelasi") +
labs(title = "Corellogram") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))
## Piecewise Constant
mod_tangga = lm(Sepal.Length ~ cut(Petal.Length,3),data=iris)
summary(mod_tangga)
##
## Call:
## lm(formula = Sepal.Length ~ cut(Petal.Length, 3), data = iris)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.0111 -0.3111 -0.0060 0.2889 1.2261
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.00600 0.06913 72.409 <2e-16 ***
## cut(Petal.Length, 3)(2.97,4.93] 0.90511 0.09594 9.434 <2e-16 ***
## cut(Petal.Length, 3)(4.93,6.91] 1.66791 0.09987 16.700 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4889 on 147 degrees of freedom
## Multiple R-squared: 0.6562, Adjusted R-squared: 0.6515
## F-statistic: 140.3 on 2 and 147 DF, p-value: < 2.2e-16
iris
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3.0 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
## 4 4.6 3.1 1.5 0.2 setosa
## 5 5.0 3.6 1.4 0.2 setosa
## 6 5.4 3.9 1.7 0.4 setosa
## 7 4.6 3.4 1.4 0.3 setosa
## 8 5.0 3.4 1.5 0.2 setosa
## 9 4.4 2.9 1.4 0.2 setosa
## 10 4.9 3.1 1.5 0.1 setosa
## 11 5.4 3.7 1.5 0.2 setosa
## 12 4.8 3.4 1.6 0.2 setosa
## 13 4.8 3.0 1.4 0.1 setosa
## 14 4.3 3.0 1.1 0.1 setosa
## 15 5.8 4.0 1.2 0.2 setosa
## 16 5.7 4.4 1.5 0.4 setosa
## 17 5.4 3.9 1.3 0.4 setosa
## 18 5.1 3.5 1.4 0.3 setosa
## 19 5.7 3.8 1.7 0.3 setosa
## 20 5.1 3.8 1.5 0.3 setosa
## 21 5.4 3.4 1.7 0.2 setosa
## 22 5.1 3.7 1.5 0.4 setosa
## 23 4.6 3.6 1.0 0.2 setosa
## 24 5.1 3.3 1.7 0.5 setosa
## 25 4.8 3.4 1.9 0.2 setosa
## 26 5.0 3.0 1.6 0.2 setosa
## 27 5.0 3.4 1.6 0.4 setosa
## 28 5.2 3.5 1.5 0.2 setosa
## 29 5.2 3.4 1.4 0.2 setosa
## 30 4.7 3.2 1.6 0.2 setosa
## 31 4.8 3.1 1.6 0.2 setosa
## 32 5.4 3.4 1.5 0.4 setosa
## 33 5.2 4.1 1.5 0.1 setosa
## 34 5.5 4.2 1.4 0.2 setosa
## 35 4.9 3.1 1.5 0.2 setosa
## 36 5.0 3.2 1.2 0.2 setosa
## 37 5.5 3.5 1.3 0.2 setosa
## 38 4.9 3.6 1.4 0.1 setosa
## 39 4.4 3.0 1.3 0.2 setosa
## 40 5.1 3.4 1.5 0.2 setosa
## 41 5.0 3.5 1.3 0.3 setosa
## 42 4.5 2.3 1.3 0.3 setosa
## 43 4.4 3.2 1.3 0.2 setosa
## 44 5.0 3.5 1.6 0.6 setosa
## 45 5.1 3.8 1.9 0.4 setosa
## 46 4.8 3.0 1.4 0.3 setosa
## 47 5.1 3.8 1.6 0.2 setosa
## 48 4.6 3.2 1.4 0.2 setosa
## 49 5.3 3.7 1.5 0.2 setosa
## 50 5.0 3.3 1.4 0.2 setosa
## 51 7.0 3.2 4.7 1.4 versicolor
## 52 6.4 3.2 4.5 1.5 versicolor
## 53 6.9 3.1 4.9 1.5 versicolor
## 54 5.5 2.3 4.0 1.3 versicolor
## 55 6.5 2.8 4.6 1.5 versicolor
## 56 5.7 2.8 4.5 1.3 versicolor
## 57 6.3 3.3 4.7 1.6 versicolor
## 58 4.9 2.4 3.3 1.0 versicolor
## 59 6.6 2.9 4.6 1.3 versicolor
## 60 5.2 2.7 3.9 1.4 versicolor
## 61 5.0 2.0 3.5 1.0 versicolor
## 62 5.9 3.0 4.2 1.5 versicolor
## 63 6.0 2.2 4.0 1.0 versicolor
## 64 6.1 2.9 4.7 1.4 versicolor
## 65 5.6 2.9 3.6 1.3 versicolor
## 66 6.7 3.1 4.4 1.4 versicolor
## 67 5.6 3.0 4.5 1.5 versicolor
## 68 5.8 2.7 4.1 1.0 versicolor
## 69 6.2 2.2 4.5 1.5 versicolor
## 70 5.6 2.5 3.9 1.1 versicolor
## 71 5.9 3.2 4.8 1.8 versicolor
## 72 6.1 2.8 4.0 1.3 versicolor
## 73 6.3 2.5 4.9 1.5 versicolor
## 74 6.1 2.8 4.7 1.2 versicolor
## 75 6.4 2.9 4.3 1.3 versicolor
## 76 6.6 3.0 4.4 1.4 versicolor
## 77 6.8 2.8 4.8 1.4 versicolor
## 78 6.7 3.0 5.0 1.7 versicolor
## 79 6.0 2.9 4.5 1.5 versicolor
## 80 5.7 2.6 3.5 1.0 versicolor
## 81 5.5 2.4 3.8 1.1 versicolor
## 82 5.5 2.4 3.7 1.0 versicolor
## 83 5.8 2.7 3.9 1.2 versicolor
## 84 6.0 2.7 5.1 1.6 versicolor
## 85 5.4 3.0 4.5 1.5 versicolor
## 86 6.0 3.4 4.5 1.6 versicolor
## 87 6.7 3.1 4.7 1.5 versicolor
## 88 6.3 2.3 4.4 1.3 versicolor
## 89 5.6 3.0 4.1 1.3 versicolor
## 90 5.5 2.5 4.0 1.3 versicolor
## 91 5.5 2.6 4.4 1.2 versicolor
## 92 6.1 3.0 4.6 1.4 versicolor
## 93 5.8 2.6 4.0 1.2 versicolor
## 94 5.0 2.3 3.3 1.0 versicolor
## 95 5.6 2.7 4.2 1.3 versicolor
## 96 5.7 3.0 4.2 1.2 versicolor
## 97 5.7 2.9 4.2 1.3 versicolor
## 98 6.2 2.9 4.3 1.3 versicolor
## 99 5.1 2.5 3.0 1.1 versicolor
## 100 5.7 2.8 4.1 1.3 versicolor
## 101 6.3 3.3 6.0 2.5 virginica
## 102 5.8 2.7 5.1 1.9 virginica
## 103 7.1 3.0 5.9 2.1 virginica
## 104 6.3 2.9 5.6 1.8 virginica
## 105 6.5 3.0 5.8 2.2 virginica
## 106 7.6 3.0 6.6 2.1 virginica
## 107 4.9 2.5 4.5 1.7 virginica
## 108 7.3 2.9 6.3 1.8 virginica
## 109 6.7 2.5 5.8 1.8 virginica
## 110 7.2 3.6 6.1 2.5 virginica
## 111 6.5 3.2 5.1 2.0 virginica
## 112 6.4 2.7 5.3 1.9 virginica
## 113 6.8 3.0 5.5 2.1 virginica
## 114 5.7 2.5 5.0 2.0 virginica
## 115 5.8 2.8 5.1 2.4 virginica
## 116 6.4 3.2 5.3 2.3 virginica
## 117 6.5 3.0 5.5 1.8 virginica
## 118 7.7 3.8 6.7 2.2 virginica
## 119 7.7 2.6 6.9 2.3 virginica
## 120 6.0 2.2 5.0 1.5 virginica
## 121 6.9 3.2 5.7 2.3 virginica
## 122 5.6 2.8 4.9 2.0 virginica
## 123 7.7 2.8 6.7 2.0 virginica
## 124 6.3 2.7 4.9 1.8 virginica
## 125 6.7 3.3 5.7 2.1 virginica
## 126 7.2 3.2 6.0 1.8 virginica
## 127 6.2 2.8 4.8 1.8 virginica
## 128 6.1 3.0 4.9 1.8 virginica
## 129 6.4 2.8 5.6 2.1 virginica
## 130 7.2 3.0 5.8 1.6 virginica
## 131 7.4 2.8 6.1 1.9 virginica
## 132 7.9 3.8 6.4 2.0 virginica
## 133 6.4 2.8 5.6 2.2 virginica
## 134 6.3 2.8 5.1 1.5 virginica
## 135 6.1 2.6 5.6 1.4 virginica
## 136 7.7 3.0 6.1 2.3 virginica
## 137 6.3 3.4 5.6 2.4 virginica
## 138 6.4 3.1 5.5 1.8 virginica
## 139 6.0 3.0 4.8 1.8 virginica
## 140 6.9 3.1 5.4 2.1 virginica
## 141 6.7 3.1 5.6 2.4 virginica
## 142 6.9 3.1 5.1 2.3 virginica
## 143 5.8 2.7 5.1 1.9 virginica
## 144 6.8 3.2 5.9 2.3 virginica
## 145 6.7 3.3 5.7 2.5 virginica
## 146 6.7 3.0 5.2 2.3 virginica
## 147 6.3 2.5 5.0 1.9 virginica
## 148 6.5 3.0 5.2 2.0 virginica
## 149 6.2 3.4 5.4 2.3 virginica
## 150 5.9 3.0 5.1 1.8 virginica
ggplot(iris,aes(x=Petal.Length, y=Sepal.Length)) +
geom_point(alpha=0.55, color="black") +
stat_smooth(method = "lm",
formula = y~cut(x,3),
lty = 1, col = "green",se = F)+
theme_bw()
Terdapat tiga kelompok titik abu-abu yang berbeda, menunjukkan adanya
tiga kelompok bunga dengan karakteristik yang berbeda berdasarkan
panjang kelopak dan kelopak daunnya. Teridentifikasi juga bahwa petal
length dan sepal length memiliki hubungan linear positif yang berarti
semakin panjang kelopak bunga maka semakin panjang pula kelompak
daun.
ggplot(iris, aes(x = Petal.Length, y = Sepal.Length)) +
geom_point(color = "blue", size = 3, alpha = 0.6) +
geom_smooth(method = "loess", color = "green", linetype = "dashed", size = 1.5) +
labs(
x = "Petal Length",
y = "Sepal Length",
title = "LOESS Visualization of Petal Length vs. Sepal Length",
subtitle = "Smoothed scatterplot with LOESS curve",
caption = "Data Iris"
) +
theme_minimal()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `geom_smooth()` using formula = 'y ~ x'
Gambar tersebut menampilkan scatter plot yang telah disesuaikan dengan
kurva LOESS, yang menggambarkan hubungan antara kedua variabel dengan
lebih halus. Kurva ini mengidentifikasi korelasi positif antar kedua
variabel. Hal ini mengindikasikan hubungan yang sejalan antara dua
variabel tersebut, yang diperkuat oleh hasil smoothing menggunakan
metode LOESS, yang menyajikan pola hubungan dengan lebih halus dan
kontinu.
data2 <- head(data2, -50)
ggplot(data2, aes(x =Date, y = Open)) +
geom_point() +
labs(title = "Scatter Plot of Time Series Data (AMC)",
x = "Date",
y = "Value (Open)")
ggplot(data2, aes(x =Date, y = Open)) +
geom_point() +
geom_line() +
labs(title = "Scatter Plot of Time Series Data (AMC)",
x = "Date",
y = "Value (open)")
ggplot(data2, aes(x =Date, y = Open)) +
geom_line() +
labs(title = "Scatter Plot of Time Series Data (AMC)",
x = "Date",
y = "Value (open)")
calculate_moving_average <- function(data2, window_size) {
ma_values <- zoo::rollmean(data2$Open, k = window_size, align = "right", fill = NA)
ma_values_padded <- c(rep(NA, window_size - 1), ma_values)
data2$ma <- ma_values_padded[1:nrow(data2)] # Extract only the necessary number of rows
return(data2)
}
window_size <- 3
data2 <- calculate_moving_average(data2, window_size)
# Create the plot
ggplot(data2, aes(x = Date)) +
geom_line(aes(y = Open), color = "white", size = 1) +
geom_line(aes(y = ma), color = "green", linetype = "dashed", size = 1) + # emulusan
geom_ribbon(aes(ymin = -Inf, ymax = ma), fill = "green", alpha = 0.2) + # Area under curve
labs(title = paste("AMC"),
x = "Date",
y = "Value (open)") +
theme_minimal()
## Warning: Removed 4 rows containing missing values or values outside the scale range
## (`geom_line()`).
data_open <- data2$Open
data.ts <- ts(data_open)
plot(data.ts, xlab ="Waktu", ylab = "Data Open AMC", col="green", main = "Plot Data Open AMC")
points(data.ts)
Grafik-grafik di atas menunjukkan pola cenderung menurun harga saham AMC
seiringan waktu
data1 <- read_csv("C:/Users/TUBAGUS/Downloads/AMC (1).csv")
## Rows: 501 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (6): Open, High, Low, Close, Adj Close, Volume
## date (1): 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.
data2 <- read_csv("C:/Users/TUBAGUS/Downloads/GME (1).csv")
## Rows: 501 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (6): Open, High, Low, Close, Adj Close, Volume
## date (1): 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.
data1 <- head(data1, -1)
data2 <- head(data2, -1)
# untuk membuat plot kedua seri waktu
ggplot() +
geom_line(data = data1, aes(x = Date, y = Open, color = "AMC")) +
geom_line(data = data2, aes(x = Date, y = Open, color = "GME")) +
labs(title = "Perbandingan Dua Data Time Series (AMC vs. GME)",
x = "Date",
y = "Value",
color = "Series") +
scale_color_manual(values = c("AMC" = "purple", "GME" = "orange")) +
theme_minimal()
Terlihat pada grafik diatas perbandingan harga saham pembukaan antara
AMC dan GME. Harga saham AMC lebih meningkat pada rentang tahun 2020
hingga 2022. Namun diakhir 2023, kedua saham tersebut telihat menurun
dan hampir sama.
world <- ne_countries(scale = "medium", returnclass = "sf")
ggplot(data = world) +
geom_sf()
ggplot(data = world) +
geom_sf(aes(fill = pop_est)) +
scale_fill_viridis_c(option = "volcano")
## Warning in viridisLite::viridis(n, alpha, begin, end, direction, option):
## Option 'volcano' does not exist. Defaulting to 'viridis'.
spasial <- read.csv("C:/Users/TUBAGUS/Downloads/2019.csv")
spasial
## Overall.rank Country.or.region Score GDP.per.capita Social.support
## 1 1 Finland 7.769 1.340 1.587
## 2 2 Denmark 7.600 1.383 1.573
## 3 3 Norway 7.554 1.488 1.582
## 4 4 Iceland 7.494 1.380 1.624
## 5 5 Netherlands 7.488 1.396 1.522
## 6 6 Switzerland 7.480 1.452 1.526
## 7 7 Sweden 7.343 1.387 1.487
## 8 8 New Zealand 7.307 1.303 1.557
## 9 9 Canada 7.278 1.365 1.505
## 10 10 Austria 7.246 1.376 1.475
## 11 11 Australia 7.228 1.372 1.548
## 12 12 Costa Rica 7.167 1.034 1.441
## 13 13 Israel 7.139 1.276 1.455
## 14 14 Luxembourg 7.090 1.609 1.479
## 15 15 United Kingdom 7.054 1.333 1.538
## 16 16 Ireland 7.021 1.499 1.553
## 17 17 Germany 6.985 1.373 1.454
## 18 18 Belgium 6.923 1.356 1.504
## 19 19 United States 6.892 1.433 1.457
## 20 20 Czech Republic 6.852 1.269 1.487
## 21 21 United Arab Emirates 6.825 1.503 1.310
## 22 22 Malta 6.726 1.300 1.520
## 23 23 Mexico 6.595 1.070 1.323
## 24 24 France 6.592 1.324 1.472
## 25 25 Taiwan 6.446 1.368 1.430
## 26 26 Chile 6.444 1.159 1.369
## 27 27 Guatemala 6.436 0.800 1.269
## 28 28 Saudi Arabia 6.375 1.403 1.357
## 29 29 Qatar 6.374 1.684 1.313
## 30 30 Spain 6.354 1.286 1.484
## 31 31 Panama 6.321 1.149 1.442
## 32 32 Brazil 6.300 1.004 1.439
## 33 33 Uruguay 6.293 1.124 1.465
## 34 34 Singapore 6.262 1.572 1.463
## 35 35 El Salvador 6.253 0.794 1.242
## 36 36 Italy 6.223 1.294 1.488
## 37 37 Bahrain 6.199 1.362 1.368
## 38 38 Slovakia 6.198 1.246 1.504
## 39 39 Trinidad & Tobago 6.192 1.231 1.477
## 40 40 Poland 6.182 1.206 1.438
## 41 41 Uzbekistan 6.174 0.745 1.529
## 42 42 Lithuania 6.149 1.238 1.515
## 43 43 Colombia 6.125 0.985 1.410
## 44 44 Slovenia 6.118 1.258 1.523
## 45 45 Nicaragua 6.105 0.694 1.325
## 46 46 Kosovo 6.100 0.882 1.232
## 47 47 Argentina 6.086 1.092 1.432
## 48 48 Romania 6.070 1.162 1.232
## 49 49 Cyprus 6.046 1.263 1.223
## 50 50 Ecuador 6.028 0.912 1.312
## 51 51 Kuwait 6.021 1.500 1.319
## 52 52 Thailand 6.008 1.050 1.409
## 53 53 Latvia 5.940 1.187 1.465
## 54 54 South Korea 5.895 1.301 1.219
## 55 55 Estonia 5.893 1.237 1.528
## 56 56 Jamaica 5.890 0.831 1.478
## 57 57 Mauritius 5.888 1.120 1.402
## 58 58 Japan 5.886 1.327 1.419
## 59 59 Honduras 5.860 0.642 1.236
## 60 60 Kazakhstan 5.809 1.173 1.508
## 61 61 Bolivia 5.779 0.776 1.209
## 62 62 Hungary 5.758 1.201 1.410
## 63 63 Paraguay 5.743 0.855 1.475
## 64 64 Northern Cyprus 5.718 1.263 1.252
## 65 65 Peru 5.697 0.960 1.274
## 66 66 Portugal 5.693 1.221 1.431
## 67 67 Pakistan 5.653 0.677 0.886
## 68 68 Russia 5.648 1.183 1.452
## 69 69 Philippines 5.631 0.807 1.293
## 70 70 Serbia 5.603 1.004 1.383
## 71 71 Moldova 5.529 0.685 1.328
## 72 72 Libya 5.525 1.044 1.303
## 73 73 Montenegro 5.523 1.051 1.361
## 74 74 Tajikistan 5.467 0.493 1.098
## 75 75 Croatia 5.432 1.155 1.266
## 76 76 Hong Kong 5.430 1.438 1.277
## 77 77 Dominican Republic 5.425 1.015 1.401
## 78 78 Bosnia and Herzegovina 5.386 0.945 1.212
## 79 79 Turkey 5.373 1.183 1.360
## 80 80 Malaysia 5.339 1.221 1.171
## 81 81 Belarus 5.323 1.067 1.465
## 82 82 Greece 5.287 1.181 1.156
## 83 83 Mongolia 5.285 0.948 1.531
## 84 84 North Macedonia 5.274 0.983 1.294
## 85 85 Nigeria 5.265 0.696 1.111
## 86 86 Kyrgyzstan 5.261 0.551 1.438
## 87 87 Turkmenistan 5.247 1.052 1.538
## 88 88 Algeria 5.211 1.002 1.160
## 89 89 Morocco 5.208 0.801 0.782
## 90 90 Azerbaijan 5.208 1.043 1.147
## 91 91 Lebanon 5.197 0.987 1.224
## 92 92 Indonesia 5.192 0.931 1.203
## 93 93 China 5.191 1.029 1.125
## 94 94 Vietnam 5.175 0.741 1.346
## 95 95 Bhutan 5.082 0.813 1.321
## 96 96 Cameroon 5.044 0.549 0.910
## 97 97 Bulgaria 5.011 1.092 1.513
## 98 98 Ghana 4.996 0.611 0.868
## 99 99 Ivory Coast 4.944 0.569 0.808
## 100 100 Nepal 4.913 0.446 1.226
## 101 101 Jordan 4.906 0.837 1.225
## 102 102 Benin 4.883 0.393 0.437
## 103 103 Congo (Brazzaville) 4.812 0.673 0.799
## 104 104 Gabon 4.799 1.057 1.183
## 105 105 Laos 4.796 0.764 1.030
## 106 106 South Africa 4.722 0.960 1.351
## 107 107 Albania 4.719 0.947 0.848
## 108 108 Venezuela 4.707 0.960 1.427
## 109 109 Cambodia 4.700 0.574 1.122
## 110 110 Palestinian Territories 4.696 0.657 1.247
## 111 111 Senegal 4.681 0.450 1.134
## 112 112 Somalia 4.668 0.000 0.698
## 113 113 Namibia 4.639 0.879 1.313
## 114 114 Niger 4.628 0.138 0.774
## 115 115 Burkina Faso 4.587 0.331 1.056
## 116 116 Armenia 4.559 0.850 1.055
## 117 117 Iran 4.548 1.100 0.842
## 118 118 Guinea 4.534 0.380 0.829
## 119 119 Georgia 4.519 0.886 0.666
## 120 120 Gambia 4.516 0.308 0.939
## 121 121 Kenya 4.509 0.512 0.983
## 122 122 Mauritania 4.490 0.570 1.167
## 123 123 Mozambique 4.466 0.204 0.986
## 124 124 Tunisia 4.461 0.921 1.000
## 125 125 Bangladesh 4.456 0.562 0.928
## 126 126 Iraq 4.437 1.043 0.980
## 127 127 Congo (Kinshasa) 4.418 0.094 1.125
## 128 128 Mali 4.390 0.385 1.105
## 129 129 Sierra Leone 4.374 0.268 0.841
## 130 130 Sri Lanka 4.366 0.949 1.265
## 131 131 Myanmar 4.360 0.710 1.181
## 132 132 Chad 4.350 0.350 0.766
## 133 133 Ukraine 4.332 0.820 1.390
## 134 134 Ethiopia 4.286 0.336 1.033
## 135 135 Swaziland 4.212 0.811 1.149
## 136 136 Uganda 4.189 0.332 1.069
## 137 137 Egypt 4.166 0.913 1.039
## 138 138 Zambia 4.107 0.578 1.058
## 139 139 Togo 4.085 0.275 0.572
## 140 140 India 4.015 0.755 0.765
## 141 141 Liberia 3.975 0.073 0.922
## 142 142 Comoros 3.973 0.274 0.757
## 143 143 Madagascar 3.933 0.274 0.916
## 144 144 Lesotho 3.802 0.489 1.169
## 145 145 Burundi 3.775 0.046 0.447
## 146 146 Zimbabwe 3.663 0.366 1.114
## 147 147 Haiti 3.597 0.323 0.688
## 148 148 Botswana 3.488 1.041 1.145
## 149 149 Syria 3.462 0.619 0.378
## 150 150 Malawi 3.410 0.191 0.560
## 151 151 Yemen 3.380 0.287 1.163
## 152 152 Rwanda 3.334 0.359 0.711
## 153 153 Tanzania 3.231 0.476 0.885
## 154 154 Afghanistan 3.203 0.350 0.517
## 155 155 Central African Republic 3.083 0.026 0.000
## 156 156 South Sudan 2.853 0.306 0.575
## Healthy.life.expectancy Freedom.to.make.life.choices Generosity
## 1 0.986 0.596 0.153
## 2 0.996 0.592 0.252
## 3 1.028 0.603 0.271
## 4 1.026 0.591 0.354
## 5 0.999 0.557 0.322
## 6 1.052 0.572 0.263
## 7 1.009 0.574 0.267
## 8 1.026 0.585 0.330
## 9 1.039 0.584 0.285
## 10 1.016 0.532 0.244
## 11 1.036 0.557 0.332
## 12 0.963 0.558 0.144
## 13 1.029 0.371 0.261
## 14 1.012 0.526 0.194
## 15 0.996 0.450 0.348
## 16 0.999 0.516 0.298
## 17 0.987 0.495 0.261
## 18 0.986 0.473 0.160
## 19 0.874 0.454 0.280
## 20 0.920 0.457 0.046
## 21 0.825 0.598 0.262
## 22 0.999 0.564 0.375
## 23 0.861 0.433 0.074
## 24 1.045 0.436 0.111
## 25 0.914 0.351 0.242
## 26 0.920 0.357 0.187
## 27 0.746 0.535 0.175
## 28 0.795 0.439 0.080
## 29 0.871 0.555 0.220
## 30 1.062 0.362 0.153
## 31 0.910 0.516 0.109
## 32 0.802 0.390 0.099
## 33 0.891 0.523 0.127
## 34 1.141 0.556 0.271
## 35 0.789 0.430 0.093
## 36 1.039 0.231 0.158
## 37 0.871 0.536 0.255
## 38 0.881 0.334 0.121
## 39 0.713 0.489 0.185
## 40 0.884 0.483 0.117
## 41 0.756 0.631 0.322
## 42 0.818 0.291 0.043
## 43 0.841 0.470 0.099
## 44 0.953 0.564 0.144
## 45 0.835 0.435 0.200
## 46 0.758 0.489 0.262
## 47 0.881 0.471 0.066
## 48 0.825 0.462 0.083
## 49 1.042 0.406 0.190
## 50 0.868 0.498 0.126
## 51 0.808 0.493 0.142
## 52 0.828 0.557 0.359
## 53 0.812 0.264 0.075
## 54 1.036 0.159 0.175
## 55 0.874 0.495 0.103
## 56 0.831 0.490 0.107
## 57 0.798 0.498 0.215
## 58 1.088 0.445 0.069
## 59 0.828 0.507 0.246
## 60 0.729 0.410 0.146
## 61 0.706 0.511 0.137
## 62 0.828 0.199 0.081
## 63 0.777 0.514 0.184
## 64 1.042 0.417 0.191
## 65 0.854 0.455 0.083
## 66 0.999 0.508 0.047
## 67 0.535 0.313 0.220
## 68 0.726 0.334 0.082
## 69 0.657 0.558 0.117
## 70 0.854 0.282 0.137
## 71 0.739 0.245 0.181
## 72 0.673 0.416 0.133
## 73 0.871 0.197 0.142
## 74 0.718 0.389 0.230
## 75 0.914 0.296 0.119
## 76 1.122 0.440 0.258
## 77 0.779 0.497 0.113
## 78 0.845 0.212 0.263
## 79 0.808 0.195 0.083
## 80 0.828 0.508 0.260
## 81 0.789 0.235 0.094
## 82 0.999 0.067 0.000
## 83 0.667 0.317 0.235
## 84 0.838 0.345 0.185
## 85 0.245 0.426 0.215
## 86 0.723 0.508 0.300
## 87 0.657 0.394 0.244
## 88 0.785 0.086 0.073
## 89 0.782 0.418 0.036
## 90 0.769 0.351 0.035
## 91 0.815 0.216 0.166
## 92 0.660 0.491 0.498
## 93 0.893 0.521 0.058
## 94 0.851 0.543 0.147
## 95 0.604 0.457 0.370
## 96 0.331 0.381 0.187
## 97 0.815 0.311 0.081
## 98 0.486 0.381 0.245
## 99 0.232 0.352 0.154
## 100 0.677 0.439 0.285
## 101 0.815 0.383 0.110
## 102 0.397 0.349 0.175
## 103 0.508 0.372 0.105
## 104 0.571 0.295 0.043
## 105 0.551 0.547 0.266
## 106 0.469 0.389 0.130
## 107 0.874 0.383 0.178
## 108 0.805 0.154 0.064
## 109 0.637 0.609 0.232
## 110 0.672 0.225 0.103
## 111 0.571 0.292 0.153
## 112 0.268 0.559 0.243
## 113 0.477 0.401 0.070
## 114 0.366 0.318 0.188
## 115 0.380 0.255 0.177
## 116 0.815 0.283 0.095
## 117 0.785 0.305 0.270
## 118 0.375 0.332 0.207
## 119 0.752 0.346 0.043
## 120 0.428 0.382 0.269
## 121 0.581 0.431 0.372
## 122 0.489 0.066 0.106
## 123 0.390 0.494 0.197
## 124 0.815 0.167 0.059
## 125 0.723 0.527 0.166
## 126 0.574 0.241 0.148
## 127 0.357 0.269 0.212
## 128 0.308 0.327 0.153
## 129 0.242 0.309 0.252
## 130 0.831 0.470 0.244
## 131 0.555 0.525 0.566
## 132 0.192 0.174 0.198
## 133 0.739 0.178 0.187
## 134 0.532 0.344 0.209
## 135 0.000 0.313 0.074
## 136 0.443 0.356 0.252
## 137 0.644 0.241 0.076
## 138 0.426 0.431 0.247
## 139 0.410 0.293 0.177
## 140 0.588 0.498 0.200
## 141 0.443 0.370 0.233
## 142 0.505 0.142 0.275
## 143 0.555 0.148 0.169
## 144 0.168 0.359 0.107
## 145 0.380 0.220 0.176
## 146 0.433 0.361 0.151
## 147 0.449 0.026 0.419
## 148 0.538 0.455 0.025
## 149 0.440 0.013 0.331
## 150 0.495 0.443 0.218
## 151 0.463 0.143 0.108
## 152 0.614 0.555 0.217
## 153 0.499 0.417 0.276
## 154 0.361 0.000 0.158
## 155 0.105 0.225 0.235
## 156 0.295 0.010 0.202
## Perceptions.of.corruption
## 1 0.393
## 2 0.410
## 3 0.341
## 4 0.118
## 5 0.298
## 6 0.343
## 7 0.373
## 8 0.380
## 9 0.308
## 10 0.226
## 11 0.290
## 12 0.093
## 13 0.082
## 14 0.316
## 15 0.278
## 16 0.310
## 17 0.265
## 18 0.210
## 19 0.128
## 20 0.036
## 21 0.182
## 22 0.151
## 23 0.073
## 24 0.183
## 25 0.097
## 26 0.056
## 27 0.078
## 28 0.132
## 29 0.167
## 30 0.079
## 31 0.054
## 32 0.086
## 33 0.150
## 34 0.453
## 35 0.074
## 36 0.030
## 37 0.110
## 38 0.014
## 39 0.016
## 40 0.050
## 41 0.240
## 42 0.042
## 43 0.034
## 44 0.057
## 45 0.127
## 46 0.006
## 47 0.050
## 48 0.005
## 49 0.041
## 50 0.087
## 51 0.097
## 52 0.028
## 53 0.064
## 54 0.056
## 55 0.161
## 56 0.028
## 57 0.060
## 58 0.140
## 59 0.078
## 60 0.096
## 61 0.064
## 62 0.020
## 63 0.080
## 64 0.162
## 65 0.027
## 66 0.025
## 67 0.098
## 68 0.031
## 69 0.107
## 70 0.039
## 71 0.000
## 72 0.152
## 73 0.080
## 74 0.144
## 75 0.022
## 76 0.287
## 77 0.101
## 78 0.006
## 79 0.106
## 80 0.024
## 81 0.142
## 82 0.034
## 83 0.038
## 84 0.034
## 85 0.041
## 86 0.023
## 87 0.028
## 88 0.114
## 89 0.076
## 90 0.182
## 91 0.027
## 92 0.028
## 93 0.100
## 94 0.073
## 95 0.167
## 96 0.037
## 97 0.004
## 98 0.040
## 99 0.090
## 100 0.089
## 101 0.130
## 102 0.082
## 103 0.093
## 104 0.055
## 105 0.164
## 106 0.055
## 107 0.027
## 108 0.047
## 109 0.062
## 110 0.066
## 111 0.072
## 112 0.270
## 113 0.056
## 114 0.102
## 115 0.113
## 116 0.064
## 117 0.125
## 118 0.086
## 119 0.164
## 120 0.167
## 121 0.053
## 122 0.088
## 123 0.138
## 124 0.055
## 125 0.143
## 126 0.089
## 127 0.053
## 128 0.052
## 129 0.045
## 130 0.047
## 131 0.172
## 132 0.078
## 133 0.010
## 134 0.100
## 135 0.135
## 136 0.060
## 137 0.067
## 138 0.087
## 139 0.085
## 140 0.085
## 141 0.033
## 142 0.078
## 143 0.041
## 144 0.093
## 145 0.180
## 146 0.089
## 147 0.110
## 148 0.100
## 149 0.141
## 150 0.089
## 151 0.077
## 152 0.411
## 153 0.147
## 154 0.025
## 155 0.035
## 156 0.091
world_map <- map_data("world")
colnames(spasial)[colnames(spasial) == "Country.Territory"] <- "region"
merged_data <- left_join(world_map, spasial, by = c("region" = "Country.or.region"))
ggplot(merged_data, aes(x = long, y = lat, group = group, fill = Perceptions.of.corruption)) +
geom_polygon(color = "black") +
scale_fill_gradient(name = "Population (2019)", low = "green", high = "red", guide = "legend") +
theme_void() +
labs(title = "Perceptions.of.corruption 2019")
Dari map chart diatas, persepsi tentang korupsi pada tahun 2019. Warna
merah/orange dan kuning menunjukkan negara-negara dengan populasi yang
banyak memberikan persepsi tentang korupsi, sementara warna hijau
menandakan populasi yang lebih rendah memberikan persepsi tentang
korupsi. Populasi yang sangat besar ada di negara Canada dan Australia.
Namun terdapat negara dengan warna abu-abu yang menandakan adanya
ketidaksesuaian dalam format nama negara dengan data yang
seharusnya.