Package yang diperlukan
library(ggplot2)
library(ggridges)
library(hrbrthemes)
## NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
## Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
## if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow
library(dplyr)
##
## 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
library(tidyr)
library(viridis)
## Loading required package: viridisLite
Mengimport Data
library(RCurl)
##
## Attaching package: 'RCurl'
## The following object is masked from 'package:tidyr':
##
## complete
x <- getURL("https://raw.githubusercontent.com/bagusco/aed2021/master/data%20economic%20freedom%202017.csv")
data <- read.csv(text = x)
Barchart dan Lolipop Chart Rata-Rata Wilayah
ratarata <- as.data.frame(tapply(data$Regulation, data$benua, mean))
colnames(ratarata) <- "Regulation"
ratarata$benua <- rownames(ratarata)
ggplot(ratarata, aes(x=benua, y=Regulation)) +
geom_bar(stat = "identity", fill=rgb(0.1,0.4,0.5,0.7))+
xlab("wilayah")

ggplot(ratarata, aes(x=benua, y=Regulation)) +
geom_segment( aes(x=benua, xend=benua, y=0, yend=Regulation), color="orange") +
geom_point( color="coral", size=5)+ xlab("wilayah")

Boxplot
ggplot(data, aes(x=benua, y=Regulation, fill=benua)) +
geom_boxplot(alpha=0.3) +
theme_light()+
theme(legend.position="none", axis.text=element_text(size=12)) +
scale_fill_brewer(palette="Set3")+
xlab("wilayah")

Density Plot - Ridgeline
ggplot(data, aes(x = Regulation, y = benua, fill = benua)) +
geom_density_ridges() +
theme_ridges() +
theme(legend.position = "none")+
ylab("wilayah")
## Picking joint bandwidth of 0.324

Density Plot - Overlaid
data2 <- data[which(data$benua=="Eropa" | data$benua == "Afrika"),]
ggplot(data=data2, aes(x=Regulation, group=benua, fill=benua)) +
geom_density(adjust=1, alpha=.3)+
xlim(3, 10)+
theme_ridges()

Violin Plot
ggplot(data, aes(x=benua, y=Regulation, fill=benua)) +
geom_violin()+
geom_boxplot(width=0.1, color="blue")+
theme(legend.position = "none", axis.text=element_text(size=12))+
scale_fill_brewer(palette="Set3")+
xlab("wilayah")
