Pendahuluan
Package Installation
library(tidyverse) #Include beberapa packages termasuk ggplot
library(dplyr)
library(reshape2)
library(htmltools)
1
Data
data <- read.csv("C:/Users/user/Downloads/cardata.csv", header = TRUE, sep=",")
str(data)
## 'data.frame': 301 obs. of 9 variables:
## $ Car_Name : chr "ritz" "sx4" "ciaz" "wagon r" ...
## $ Year : int 2014 2013 2017 2011 2014 2018 2015 2015 2016 2015 ...
## $ Selling_Price: num 3.35 4.75 7.25 2.85 4.6 9.25 6.75 6.5 8.75 7.45 ...
## $ Present_Price: num 5.59 9.54 9.85 4.15 6.87 9.83 8.12 8.61 8.89 8.92 ...
## $ Kms_Driven : int 27000 43000 6900 5200 42450 2071 18796 33429 20273 42367 ...
## $ Fuel_Type : chr "Petrol" "Diesel" "Petrol" "Petrol" ...
## $ Seller_Type : chr "Dealer" "Dealer" "Dealer" "Dealer" ...
## $ Transmission : chr "Manual" "Manual" "Manual" "Manual" ...
## $ Owner : int 0 0 0 0 0 0 0 0 0 0 ...
Visualisasi
Korelasi
ggplot(data, aes(x = Present_Price, y = Kms_Driven)) +
geom_point() +
labs(title = "Scatter Plot", x = "Harga Sekarang", y = "Total KM") +
theme_classic()

data$Car_Name <- ifelse(data$Kms_Driven >= 50000, "KM > 50000", "KM < 50000")
ggplot(data, aes(x = Present_Price, y = Kms_Driven, color = Car_Name)) +
geom_point() +
labs(title = "Scatter Plot Mobil KM dibawah 50000 dan diatas 50000", x = "Harga", y = "KM", color = "Kategori") +
theme_minimal()

ggplot(data, aes(x = Present_Price, y = Kms_Driven, color = Car_Name)) +
geom_point() +
labs(title = "Scatter Plot Rumah Tahun 2000an dan 90an", x = "Present_Price", y = "Kms_Driven", color = "Kategori") +
facet_wrap(~ Car_Name) +
theme_minimal()

2
generate_random_walk <- function(n, start = 0, sd = 1) {
steps <- rnorm(n, mean = 0, sd = sd)
walk <- cumsum(steps) + start
return(walk)
}
set.seed(179)
dates <- seq(as.Date("2020-01-01"), by = "month", length.out = 500)
values <- generate_random_walk(500, start = 100, sd = 10)
time_series_data <- data.frame(date = dates, value = values)
ggplot(time_series_data, aes(x = date, y = value)) +
geom_point() +
labs(title = "Scatter Plot of Time Series Data",
x = "Date",
y = "Value")

ggplot(time_series_data, aes(x = date, y = value)) +
geom_line() +
labs(title = "Random Walk Time Series Plot",
x = "Date",
y = "Value")

3
EUcor <- read.csv("C:/Users/user/Downloads/eropa corona.csv")
dataworld <- map_data("world")
dataEU <- left_join(dataworld, EUcor, by="region")
dataEU_cor <- dataEU %>% filter(!is.na(dataEU$Corona))
ggplot(dataEU_cor, aes( x = long, y = lat, group=group)) +
geom_polygon(aes(fill = Corona), color = "black")+
scale_fill_gradient(name = "Positif", low = "lightblue", high = "blue", na.value = "green")+
theme(axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.y=element_blank(),
axis.title.x=element_blank(),
rect = element_blank())
