Anda di halaman 1dari 5

data <- read.csv("D://bigdata.

csv", header=T)

data

summary(data)

#histogram

hist(data$Cost.Price...US.)

#interpretasi histogram

a <- hist(data$Cost.Price...US.)

#mengubah scale frequensi(y) menjadi densitas

hist(data$Cost.Price...US., freq = F)

#densitas peluang utk selang yang diberikan, f(x) dari var x

density(data$Cost.Price...US.)

sd <- density(data$Cost.Price...US.)

plot(sd)

#memberi garis pada histogram dan plot

lines(sd)

lines(a)

#histogram breaks, range scale x sebesar 14

hist(data$Cost.Price...US., breaks=14)

b <- hist(data$Cost.Price...US., breaks=14)

#main =meberi judul, col=color=memberi warna

hist(data$Cost.Price...US., breaks=14, col=7, main="histogram of cost price")

#memberi warna histogram, brewer.pal(berapa kolom yang akan diwarnai, jenis warna),

#accent=kualitatif palette

library(RColorBrewer)
par(mfrow=c(2,2))

hist(data$Cost.Price...US., breaks=14, col=brewer.pal(3,"Set1"), main="histogram of cost price")

hist(data$Cost.Price...US., breaks=14, col=brewer.pal(4,"Set2"), main="histogram of cost price")

hist(data$Cost.Price...US., breaks=14, col=brewer.pal(3,"Accent"), main="histogram of cost price")

hist(data$Cost.Price...US., breaks=14, col=brewer.pal(3,"Set3"), main="histogram of cost price")

#scaterplot=jelak=skan pola hubungan,data ABCSales

cap_data <- read.csv("D://ABCSales.csv", sep=";", header=T)

cap_data

plot(x=cap_data$Advertis, y=cap_data$Sales)

plot(x=cap_data$Advertis, y=cap_data$Sales, col=brewer.pal(3,"Set1"))

plot(x=cap_data$Advertis, y=cap_data$Sales, col=brewer.pal(3,"Set2"))

plot(x=cap_data$Advertis, y=cap_data$Sales, col=brewer.pal(3,"Set3"))

plot(x=cap_data$Advertis, y=cap_data$Sales, col=brewer.pal(3,"Pastel1"))

#boxplot

boxplot(cap_data$Advertis)

boxplot(cap_data$Advertis, col=brewer.pal(3,"Pastel1"))

as <- boxplot(cap_data$Advertis)

summary(as)

names(as)

as$stats

barplot(cap_data$Advertis)

#cap_data[baris,colom], pairs=hubungan antar variabel

pairs(cap_data[,2:4])

ad <- cap_data$Advertis

#normalqqplot
qqnorm(ad, col=brewer.pal(3,"Pastel1"))

qqline(ad)

#membagi pada lembar plot 3 baris 3 kolom ketika memunculkan gambar

par(mfrow=c(3,3))

#librari lattice

library(lattice)

data("iris")

data

bwplot(Sepal.Width~Sepal.Length,data=iris)

dotplot(Sepal.Width~Sepal.Length,data=iris)

xyplot(Sepal.Width~Sepal.Length,data=iris)

xyplot(Sepal.Width~Sepal.Length|Species,data=iris)

xyplot(Sepal.Width~Sepal.Length|Petal.Width,data=iris)

#librari psych

library(psych)

pairs.panels(iris)

pairs.panels(iris,ellipses = F)

#GGplot

library(ggplot2)

data <- read.csv("D://mpg.csv", header = T)

data

#scaterplot, geom_point=scaterplot, geom_smooth=memberi garis

g<-ggplot(mpg,aes(cty,hwy))

g+geom_point()+geom_smooth(method="lm",se=F)
#JitterPlot, theme_set=merubah warna tema sepenuhnya, theme_bw=warna brown, aes=variabel

#jiter sama point tetapi jiter lebih memberi banyak titik2 variabel acak ke lokasi titik(overplotng)

theme_set(theme_bw())

theme_set(theme_dark())

g<-ggplot(mpg,aes(cty,hwy))

g+geom_jitter(width=.5,size=1)

#CountChartmenghitung jumlah observasi di setiap lokasi, lalu memetakan hitungan

#ke area titik. Ini berguna ketika Anda memiliki data diskrit dan overplotting.

g<-ggplot(mpg,aes(cty,hwy))

g+geom_count(col="red",show.legend=F)

#bubbleplot

mpg_select<-mpg[mpg$manufacturer%in%c("audi","ford","honda","hyundai"),]

theme_set(theme_bw())

g<-ggplot(mpg_select,aes(displ,cty))

g+geom_jitter(aes(col=manufacturer,size=hwy))+geom_smooth(aes(col=manufacturer),method="lm",se
=F)

#Correlogram, lab=muncul nilai, type lower dari rendah, method= jenis

#round(cor(data),decimal)

library(ggcorrplot)

data(mtcars)

corr<-round(cor(mtcars),1)

library(ggcorrplot)

data(mtcars)

corr <- round(cor(mtcars), 1)

corr

ggcorrplot(corr,method=c("square"),type="lower",ggtheme =theme_dark,title="Correlogram of mtcars",


hc.order = F,lab=TRUE, lab_size=3,colors=c("blue","white","red"))

ggcorrplot(corr,method=c("circle"),type="lower",ggtheme =theme_dark,title="Correlogram of mtcars",

hc.order = F,lab=TRUE, lab_size=3,colors=c("blue","white","red"))

library(animation)

library(gganimate)

library(cowplot)

Anda mungkin juga menyukai