load("D:/OLC_731/DATA/miniPISA.rda")
load("D:/OLC_731/DATA/PISA_OGR_2018.rda")
load("D:/OLC_731/DATA/midiPISA.rda")
library(expss)
## Loading required package: maditr
##
## To aggregate several columns with one summary: take(mtcars, mpg, hp, fun = mean, by = am)
##
## Attaching package: 'expss'
## The following object is masked from 'package:ggplot2':
##
## vars
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:expss':
##
## compute, contains, na_if, recode, vars, where
## The following objects are masked from 'package:maditr':
##
## between, coalesce, first, last
## The following object is masked from 'package:kableExtra':
##
## group_rows
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyr)
##
## Attaching package: 'tidyr'
## The following objects are masked from 'package:expss':
##
## contains, nest
library(tibble)
library(haven)
##
## Attaching package: 'haven'
## The following objects are masked from 'package:expss':
##
## is.labelled, read_spss
library(sjlabelled)
##
## Attaching package: 'sjlabelled'
## The following objects are masked from 'package:haven':
##
## as_factor, read_sas, read_spss, read_stata, write_sas, zap_labels
## The following object is masked from 'package:dplyr':
##
## as_label
## The following object is masked from 'package:expss':
##
## read_spss
## The following object is masked from 'package:ggplot2':
##
## as_label
library(psych)
##
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
library(pastecs)
##
## Attaching package: 'pastecs'
## The following object is masked from 'package:tidyr':
##
## extract
## The following objects are masked from 'package:dplyr':
##
## first, last
## The following objects are masked from 'package:maditr':
##
## first, last
midiPISA %>%
# "O_" başlayan ve "OD" içeren değişkenlerin seçimi
select(starts_with("OD") & contains("MA")) %>%
lapply(.,sd) # her bir değişkenin standart sapmasının hesaplanması
## $ODOKUMA1
## [1] 87.78006
##
## $ODOKUMA2
## [1] 87.696
##
## $ODOKUMA3
## [1] 87.07692
##
## $ODOKUMA4
## [1] 87.40305
##
## $ODOKUMA5
## [1] 87.21323
midiPISA %>%
select(starts_with("OD") & contains("MA")) %>%
summarise(across(everything(), list(sd = sd),na.rm=TRUE))
## Warning: There was 1 warning in `summarise()`.
## ℹ In argument: `across(everything(), list(sd = sd), na.rm = TRUE)`.
## Caused by warning:
## ! The `...` argument of `across()` is deprecated as of dplyr 1.1.0.
## Supply arguments directly to `.fns` through an anonymous function instead.
##
## # Previously
## across(a:b, mean, na.rm = TRUE)
##
## # Now
## across(a:b, \(x) mean(x, na.rm = TRUE))
# her bir değişkenin standart sapmasının hesaplanması
#group_by ile de yapılabilir
describe(midiPISA %>%
select(CINSIYET,ODOKUMA1)) # özetleyici istatistiklerinin hesaplanması
round(stat.desc(midiPISA %>%
select(CINSIYET,OKUMA_ZEVK)),2) # değişkenlik katsayısının hesaplanması
tab <- table(midiPISA$Anne_Egitim) # her benzersiz değer için oluşum sayısı
tab
##
## 0 1 2 3 4 5 6
## 695 1882 1362 575 675 759 887
library(dplyr)
midiPISA %>%
group_by(Anne_Egitim) %>% # Anne_Egitim e göre gruplandırma
count() %>% # frekans tablosu oluşturma
ungroup() # gruplandırmanın kaldırılması
midiPISA %>%
summarise(ort = mean(ODOKUMA1), # ortalama
sd = sd(ODOKUMA1), # standart sapma
n = n()) # frekans hesaplama
# install.packages("tidyverse", repos="https://cran.rstudio.com") # paketin yüklenmesi
library("tidyverse") # paketin aktifleştirilmesi
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.0 ✔ readr 2.1.5
## ✔ lubridate 1.9.3 ✔ stringr 1.5.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ psych::%+%() masks ggplot2::%+%()
## ✖ psych::alpha() masks ggplot2::alpha()
## ✖ forcats::as_factor() masks sjlabelled::as_factor(), haven::as_factor()
## ✖ sjlabelled::as_label() masks dplyr::as_label(), ggplot2::as_label()
## ✖ dplyr::between() masks maditr::between()
## ✖ dplyr::coalesce() masks maditr::coalesce()
## ✖ readr::cols() masks maditr::cols()
## ✖ dplyr::compute() masks expss::compute()
## ✖ tidyr::contains() masks dplyr::contains(), expss::contains()
## ✖ pastecs::extract() masks tidyr::extract()
## ✖ dplyr::filter() masks stats::filter()
## ✖ pastecs::first() masks dplyr::first(), maditr::first()
## ✖ stringr::fixed() masks expss::fixed()
## ✖ dplyr::group_rows() masks kableExtra::group_rows()
## ✖ haven::is.labelled() masks expss::is.labelled()
## ✖ purrr::keep() masks expss::keep()
## ✖ dplyr::lag() masks stats::lag()
## ✖ pastecs::last() masks dplyr::last(), maditr::last()
## ✖ purrr::modify() masks expss::modify()
## ✖ purrr::modify_if() masks expss::modify_if()
## ✖ dplyr::na_if() masks expss::na_if()
## ✖ tidyr::nest() masks expss::nest()
## ✖ sjlabelled::read_sas() masks haven::read_sas()
## ✖ sjlabelled::read_spss() masks haven::read_spss(), expss::read_spss()
## ✖ sjlabelled::read_stata() masks haven::read_stata()
## ✖ dplyr::recode() masks expss::recode()
## ✖ stringr::regex() masks expss::regex()
## ✖ purrr::transpose() masks maditr::transpose()
## ✖ dplyr::vars() masks expss::vars(), ggplot2::vars()
## ✖ purrr::when() masks expss::when()
## ✖ dplyr::where() masks expss::where()
## ✖ sjlabelled::write_sas() masks haven::write_sas()
## ✖ sjlabelled::zap_labels() masks haven::zap_labels()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
#base paketini evde kendin çalıştır
library(dplyr)
library(magrittr)
##
## Attaching package: 'magrittr'
## The following object is masked from 'package:purrr':
##
## set_names
## The following object is masked from 'package:pastecs':
##
## extract
## The following object is masked from 'package:tidyr':
##
## extract
## The following objects are masked from 'package:expss':
##
## and, equals, not, or
library(haven)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
load("D:/OLC_731/DATA/PISA_OGR_2018.rda")
miniPISA <- PISA_OGR_2018 %>%
select(CINSIYET, SINIF,KITAPSAYISI, SES, Anne_Egitim, Baba_Egitim,Okuloncesi_yil,OKUL_TUR,OKUMA_ZEVK,
OK_YETERLIK,ODOKUMA1)
# kategorik değişkenlerin faktör olarak kaydı
miniPISA<- miniPISA %>% mutate_if(is.labelled, sjlabelled::as_factor)
#etiketli spps verileri için kullanabiliriz
# Faktör değiskenlere düzey atama amacıyla yazılan fonksiyon
levelsnames <- function(x){
levels(x) <- names(attr(x,"labels"))
x
}
# yazılan fonksiyonun faktör değişkenlere uygulanması
miniPISA <-mutate_if(miniPISA,is.factor, levelsnames)
head(miniPISA)
library(ggplot2)
#qplot(x, y, data, geom) #quik fonksiyonu
#ggplot(x, y, data, geom) # yapmak istediklerimizi %>% yerine + kullanıyoruz
#ggplot( data, aes(x, y)) + geom.grafikismi() #temel sistemin oluşturulması
#ggplot(x, y, data, geom="density")
#ggplot( data, aes(x, y)) + geom.density()
ggplot(miniPISA, aes(x=ODOKUMA1))+
geom_density()
ggplot(miniPISA, aes(x=ODOKUMA1))+
geom_density(linetype="dashed", fill="pink") +theme_light()
?linetype #0 = blank, 1 = solid, 2 = dashed, 3 = dotted, 4 = dotdash, 5 = longdash, 6 = twodash
## starting httpd help server ... done
grafik_1 <- ggplot(miniPISA, aes(x=ODOKUMA1))+ geom_histogram() #ilk katmanın oluşturulması
grafik_1 # oluşturulan nesnenin kaydedilmesi
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#+ geom ile yemi katmanlar eklenir
grafik_1 +
geom_histogram() +
facet_wrap(~CINSIYET, ncol=2) # cinsiyet değişkenindeki faktörlerin sütunda yer alması
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
grafik_1 +
geom_histogram() +
facet_wrap(~CINSIYET, nrow=2) # cinsiyet değişkenindeki faktörlerin sütunda yer alması
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#facet_grid(satırdeğişkeni~sütundeğişkeni)
#facet_grid(satırdeğişkeni~.)
#facet_grid(.~sütundeğişkeni)
#çapraz tablo gibi grafik oluşturma
library(haven)
miniPISA <-
miniPISA %>%
mutate_if(is.labelled, funs(as_factor(.)))
## Warning: `funs()` was deprecated in dplyr 0.8.0.
## ℹ Please use a list of either functions or lambdas:
##
## # Simple named list: list(mean = mean, median = median)
##
## # Auto named with `tibble::lst()`: tibble::lst(mean, median)
##
## # Using lambdas list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
ggplot(miniPISA, aes(x=ODOKUMA1)) +
geom_histogram()+ #histogram çizilmesi
facet_grid(SINIF~CINSIYET) # sınıf ve cinsiyete göre yüzey eklenmesi
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
miniPISA %>% filter( SINIF== "SINIF 9") %>%
ggplot(miniPISA %>% filter( SINIF=="SINIF 9") , aes (x= ODOKUMA1)) +
geom_histogram()+ #histogram çizilmesi
facet_wrap( ~CINSIYET) + theme_apa()
##color ile gruplandırma
p1 <- ggplot(
miniPISA %>%
group_by(SINIF,CINSIYET) %>%
mutate(ort=mean(ODOKUMA1)) %>% # ortalama puanların sütun olarak ekleme
ungroup(), # gruplamanın iptal edilmesi
aes(x=SINIF, y=ort, color=CINSIYET )) + # cinsiyete göre sınıf düzeyinde ortalamaların verilmesi
geom_point() + #saçılım grafiği oluşturma
xlab("Sınıf Düzeyi")+ # x eksenine etiket verilmesi
ylab("Ortalama Puan") #y eksenine etiket verilmesi
p1 # nesnenin kaydedilmesi
p1+ggtitle("Cinsiyet ve Sınıf Düzeyine Göre Ortalama" )
ggplot(miniPISA,aes(x=ODOKUMA1, y=OKUMA_ZEVK, color=CINSIYET)) +
geom_point() + #saçılım grafiği çizilmesi
facet_grid(.~SINIF) #yüzey ekleme birden fazla sütun
## Warning: Removed 69 rows containing missing values or values outside the scale range
## (`geom_point()`).
p2 <- ggplot(miniPISA, aes(x=SINIF, y=ODOKUMA1)) + # x ve y eksenlerini belirleme
geom_point() # saçılım grafiği çizme
p2
ggplot(miniPISA, aes(CINSIYET, OK_YETERLIK)) +
geom_point(color = "purple") # saçılım grafiğinin rengini seçme
## Warning: Removed 199 rows containing missing values or values outside the scale range
## (`geom_point()`).
ggplot(miniPISA, aes(CINSIYET, OK_YETERLIK)) +
geom_point(color = "blue",size=5, shape="a") # saçılım grafiğinin rengini, size büyüklük
## Warning: Removed 199 rows containing missing values or values outside the scale range
## (`geom_point()`).
ggplot(miniPISA, aes(SINIF, OK_YETERLIK, color = CINSIYET)) + # cinsiyete göre gruplandırma
geom_point() # saçılılm grafiği çizme
## Warning: Removed 199 rows containing missing values or values outside the scale range
## (`geom_point()`).
ggplot(miniPISA, aes(SINIF, OK_YETERLIK, color = CINSIYET)) + # cinsiyete göre renk
# açısından gruplandırma
geom_point(position = "jitter") # üst üste gelen noktaları kaydırma
## Warning: Removed 199 rows containing missing values or values outside the scale range
## (`geom_point()`).
ggplot(miniPISA, aes(CINSIYET, OK_YETERLIK, size = SINIF)) + #sınıf değişkenine göre büyüklük
# açısından gruplandırma
geom_point() #saçılım grafiği çizme
## Warning: Using size for a discrete variable is not advised.
## Warning: Removed 199 rows containing missing values or values outside the scale range
## (`geom_point()`).
# sınıf değişkenine göre büyüklük açısından gruplandırma
ggplot(miniPISA, aes(CINSIYET, OK_YETERLIK, size = SINIF)) +
geom_point(position = "jitter") # üst üste gelen noktaları kaydırma
## Warning: Using size for a discrete variable is not advised.
## Warning: Removed 199 rows containing missing values or values outside the scale range
## (`geom_point()`).
ggplot(miniPISA, aes(CINSIYET, OK_YETERLIK, size = SINIF)) +
geom_point(position = position_jitter(width = 0.2, height = 0.1))
## Warning: Using size for a discrete variable is not advised.
## Warning: Removed 199 rows containing missing values or values outside the scale range
## (`geom_point()`).
ggplot(miniPISA, aes(ODOKUMA1, OK_YETERLIK, color = SINIF)) +
geom_point(alpha = 0.3)
## Warning: Removed 199 rows containing missing values or values outside the scale range
## (`geom_point()`).
grafik1 <- ggplot(miniPISA, aes(ODOKUMA1, OK_YETERLIK, color = SINIF))
grafik1 +geom_point(alpha = 1.2)
## Warning: Removed 199 rows containing missing values or values outside the scale range
## (`geom_point()`).
ggplot(miniPISA[1:10,], aes(ODOKUMA1, OK_YETERLIK))+
geom_text(aes(label = CINSIYET))
## Scale
#x eksenin kategorik veya sürekli olmasına göre değişiklik gösterebilir.
#eksen limeitlerini ve düzeylerini düzenlemek için kullanılır.
sekiller <- data.frame(sekil = 0:24)
ggplot(sekiller, aes(0, 0, shape = sekil)) +
geom_point(aes(shape = sekil), size = 5, fill = 'red') +
scale_shape_identity() +
facet_wrap(~sekil) +
theme_void()
ggplot(miniPISA, aes(x = ODOKUMA1,y = OK_YETERLIK, color = CINSIYET)) +
geom_point(position = "jitter") +
scale_color_manual(values = c("red", "blue")) #defult turuncu ve yeşildi değiştirmek için kod
## Warning: Removed 199 rows containing missing values or values outside the scale range
## (`geom_point()`).
ggplot(miniPISA, aes(x = ODOKUMA1,y = OK_YETERLIK,color = CINSIYET)) + # cinsiyete göre gruplandırma
geom_point(position = "jitter") + # üst üste gelen noktaları kaydırma
scale_x_continuous("Okuma Puanları",limits = c(100,900)) + # x eksenindeki okuma puanlarını sınırlandırma
scale_color_discrete("Cinsiyet",labels=c("KIZ","ERKEK")) # cinsiyete göre scale_color_discrete yeniden adlandırma
## Warning: Removed 199 rows containing missing values or values outside the scale range
## (`geom_point()`).
ggplot(miniPISA, aes(x = ODOKUMA1,
y = OK_YETERLIK,
color = CINSIYET)) +
geom_point(position = "jitter") +
scale_x_continuous("Okuma Puanları",limits = c(100,900),
breaks=seq(100,900,100)) + #100 er 100 er artırma
scale_color_discrete("Cinsiyet")
## Warning: Removed 199 rows containing missing values or values outside the scale range
## (`geom_point()`).
ggplot(miniPISA, aes(x = ODOKUMA1,
y = OK_YETERLIK,
color = CINSIYET)) +
geom_point(position = "jitter") +
scale_x_continuous("Okuma Puanları",limits = c(100,900),
breaks=seq(100,900,100), expand=c(0,0)) + #sınırları gerçek değerde tutma
scale_color_discrete("Cinsiyet")
## Warning: Removed 199 rows containing missing values or values outside the scale range
## (`geom_point()`).
#isimlendirme yapma
ggplot(miniPISA, aes(x = ODOKUMA1,
y = OK_YETERLIK,
color = CINSIYET)) +
geom_point(position = "jitter") +
labs(x = "\nBasari Puanları", #\n boşluk bırakma
y = "\n\nYeterlik Puanları",
color = "Grup")
## Warning: Removed 199 rows containing missing values or values outside the scale range
## (`geom_point()`).
ggplot(miniPISA, aes(CINSIYET, fill = SINIF)) + geom_bar() + # bar grafiği
labs(x = "Cinsiyet",
y = "Frekans") #etiketleme yapılması
#Birden fazla kategorik değişkenin gösterilmesi ; bar
ggplot(data = miniPISA, mapping = aes(x = CINSIYET)) + #aes ile yaptığımız şey mapp'in işlevleri
geom_bar()
ggplot(data = miniPISA, mapping = aes(x = CINSIYET)) +
geom_bar(aes(y = (..count..)/sum(..count..)))+
scale_y_continuous(name = "Yüzde", labels=scales::percent) # "scales ::" paketi etkinleştirmeden işlevi kullanma
## Warning: The dot-dot notation (`..count..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(count)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
ggplot(data = miniPISA, mapping = aes(x = CINSIYET)) +
geom_bar(aes(y = (..count..)/sum(..count..)))+
scale_y_continuous(name = "Yüzde", labels=scales::percent)
ggplot(miniPISA, aes(CINSIYET, fill = SINIF)) +
geom_bar() +
labs(x = "Cinsiyet",
y = "Frekans") +
scale_fill_manual("CINSIYET", values = c("red","blue","orange","green", #kategorinin renklerini değiştirme
"darkblue","purple"))