library (gapminder)
## Warning: package 'gapminder' was built under R version 4.5.2
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 (ggplot2)
## Warning: package 'ggplot2' was built under R version 4.5.2
ulke (country)
yil (year)
yasam_beklentisi (lifeExp)
kisi_basi_gelir (gdpPercap)
kita (continent)
eğim (β₁)
kesişim (β₀)
R-kare (R²)
geom_jitter fonksiyonunun kullanım amacı
nedir?library(dplyr)
library(ggplot2)
library(gapminder)
data("gapminder")
names(gapminder)
## [1] "country" "continent" "year" "lifeExp" "pop" "gdpPercap"
glimpse(gapminder)
## Rows: 1,704
## Columns: 6
## $ country <fct> "Afghanistan", "Afghanistan", "Afghanistan", "Afghanistan", …
## $ continent <fct> Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia, …
## $ year <int> 1952, 1957, 1962, 1967, 1972, 1977, 1982, 1987, 1992, 1997, …
## $ lifeExp <dbl> 28.801, 30.332, 31.997, 34.020, 36.088, 38.438, 39.854, 40.8…
## $ pop <int> 8425333, 9240934, 10267083, 11537966, 13079460, 14880372, 12…
## $ gdpPercap <dbl> 779.4453, 820.8530, 853.1007, 836.1971, 739.9811, 786.1134, …
gapminder_tr <- gapminder %>%
rename(
ulke = country,
yil = year,
yasam_beklentisi = lifeExp,
kisi_basi_gelir = gdpPercap,
kita = continent,
)
gapminder_tr <- gapminder_tr |>
select(ulke, yil, yasam_beklentisi, kisi_basi_gelir, kita) |>
na.omit()
ggplot(gapminder_tr, aes(x = ulke,
y = yasam_beklentisi)) +
geom_point() +
labs(x = "Ülke",
y = "yasŞm beklentisi",
title = "ulke ile yaşam_beklentisi ilişkisi")
gap_mod <- lm(formula = ulke ~ yasam_beklentisi, data = gapminder_tr)
## Warning in model.response(mf, "numeric"): using type = "numeric" with a factor
## response will be ignored
## Warning in Ops.factor(y, z$residuals): '-' not meaningful for factors
#summary(gap_mod) #hocam hata verdi
coef(gap_mod)
## (Intercept) yasam_beklentisi
## 59.9151611 0.1947869
ggplot(gapminder_tr, aes(x = ulke, y = yasam_beklentisi)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "red") +
labs(x = "ulke",
y = "yasam_beklentisi",
title = "Basit doğrusal regresyon çizgisi")
## `geom_smooth()` using formula = 'y ~ x'
new_gap <- data.frame(yasam_beklentisi = 80)
predict(gap_mod, newdata = new_gap)
## 1
## 75.49811
ggplot(gapminder_tr, aes(x = ulke, y= yasam_beklentisi)) +
geom_jitter(width = 0.3, height = 0.3, alpha = 0.5, color = "steelblue") +
geom_point(alpha = 0.5, size = 3, color = "steelblue") +
geom_smooth(method = "lm", se = FALSE, color = "red") +
labs(
x = "ulke",
y = "yasam_beklentisi",
title = "Basit dogrusal regresyon"
) +
theme_classic() +
theme(
plot.title = element_text(size = 20, face = "bold"),
axis.title = element_text(size = 12),
axis.text = element_text(size = 20)
)
## `geom_smooth()` using formula = 'y ~ x'