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(ggpubr)
## Loading required package: ggplot2
library(sjlabelled)
##
## Attaching package: 'sjlabelled'
## The following object is masked from 'package:ggplot2':
##
## as_label
## The following object is masked from 'package:dplyr':
##
## as_label
library(haven)
##
## Attaching package: 'haven'
## The following objects are masked from 'package:sjlabelled':
##
## as_factor, read_sas, read_spss, read_stata, write_sas, zap_labels
library(tidyr)
library(ggplot2)
#veriye goz atma
glimpse(mtcars)
## Rows: 32
## Columns: 11
## $ mpg <dbl> 21.0, 21.0, 22.8, 21.4, 18.7, 18.1, 14.3, 24.4, 22.8, 19.2, 17.8,…
## $ cyl <dbl> 6, 6, 4, 6, 8, 6, 8, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 8,…
## $ disp <dbl> 160.0, 160.0, 108.0, 258.0, 360.0, 225.0, 360.0, 146.7, 140.8, 16…
## $ hp <dbl> 110, 110, 93, 110, 175, 105, 245, 62, 95, 123, 123, 180, 180, 180…
## $ drat <dbl> 3.90, 3.90, 3.85, 3.08, 3.15, 2.76, 3.21, 3.69, 3.92, 3.92, 3.92,…
## $ wt <dbl> 2.620, 2.875, 2.320, 3.215, 3.440, 3.460, 3.570, 3.190, 3.150, 3.…
## $ qsec <dbl> 16.46, 17.02, 18.61, 19.44, 17.02, 20.22, 15.84, 20.00, 22.90, 18…
## $ vs <dbl> 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0,…
## $ am <dbl> 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0,…
## $ gear <dbl> 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 4, 4, 4, 3, 3,…
## $ carb <dbl> 4, 4, 1, 1, 2, 1, 4, 2, 2, 4, 4, 3, 3, 3, 4, 4, 4, 1, 2, 1, 1, 2,…
veri seti tanıtımı mtcars veri seti 11 degiskeden olusmakta, 1973-74 model 32 otomobilin yakıt tüketimi ve otomobil tasarımı ve performansının 10 yonunu icermektedir.
mpg:Mil/ABD galonu cyl: silindir sayısı disp: yer degistirme hp: brut beygr gucu drat: arka aks oranı wt: agırlık(1000 lbs) qsec: 1/4 mil zaman vs: V/S am: sanzıman(0= otomatik, 1=manuel) gear: ileri vites sayısı carb: karburator sayısı
vites turune gore yakıt tuketimleri ve beygir gucleri veri setinde mpg degıskeni yakıt tuketimini, am degiskeni vites tipini ve hp degiskeni ise beygir gucunu gostermektedir.
ggplot(mtcars, aes( x= wt, y=mpg)) +
geom_line(aes(group=1), color="red")+
geom_point(color="blue")+
theme_minimal()+
labs(title = "MPG ve arac agırlıgı",
x="agırlık(1000 lbs)",
y="mil basına galon")
ggplot(mtcars, aes(x=wt, y= mpg)) +
geom_point() +
geom_smooth(method="lm", se=FALSE) +
theme_minimal()+
labs(title= "MPG'nin Arac agırlıgına karsı regresyonu",
subtitle = "Guven aralıgı olmadan",
x= "agırlık(1000 lbs)",
y="mil/galon")
## `geom_smooth()` using formula = 'y ~ x'
silindirin renk gruplandırması
mtcars$cyl <- as.factor(mtcars$cyl)
ggplot(mtcars, aes(x=wt, y= mpg, color= cyl)) +
geom_point(size=3) +
theme_minimal()+
labs(title= "MPG ve silindir sayısına gore Arac agırlıgı",
subtitle = "Guven aralıgı olmadan",
x= "agırlık(1000 lbs)",
y="mil/galon",
color="cyl")+
scale_color_manual(values=c("4"="blue", "6"="green","8"="red"))
ggscatter(mtcars, x="mpg", y="wt",
add="reg.line", conf.int= TRUE,
cor.coef = TRUE, cor.method = "pearson",
xlab="MİLES/US gallon", ylab="weight")