Mandy
30.05.2016
We learned about
Example:
setwd("/media/mandy/Volume/transcend/life/2016kurs/session2")
library(package.name)
library(MASS)
R can import data of different forms, from different file types, etc. It is important to remember: for almost every kind of file type you have to use a different function, e.g.
File Type | function to load the data | package |
---|---|---|
.rdata (R's own format) | load() | base |
.csv (English) | read.csv() | base |
.csv (German) | read.csv() | base |
.txt | read.table() | base |
.xlsx | read_excel() | readxl |
.sav (SPSS) | spss.get() | Hmisc |
.dta (Stata) | stata.get() | Hmisc |
.sasbdat (SAS) | sas.get() | Hmisc |
.sasxport (SAS Transport Files) | sasxport.get() | Hmisc |
library(readxl)
x1 <- read_excel("data/20160523evaluation_Kopie.xlsx",1)
x2 <- read_excel("data/20160523evaluation_Kopie.xlsx",2)
x3 <- read_excel("data/20160523evaluation_Kopie.xlsx",3)
x4 <- read_excel("data/20160523evaluation_Kopie.xlsx",4)
library(Hmisc)
yy <- spss.get("data/mz2010_cf.sav")
table(yy$EF310)
library(ggplot2)
ggplot(yy, aes(x = EF310)) +
geom_bar()
ggplot(yy, aes(x = EF310, colour = EF46)) +
geom_bar()
ggplot(yy, aes(x = EF310, colour = EF46)) +
geom_bar(position = "dodge")
ggplot(yy, aes(x = EF310, colour = EF46)) +
geom_bar(position = "fill")
ggplot(yy, aes(x = EF310, fill = EF46)) +
geom_bar(position = "fill")
ggplot(yy, aes(x = EF310, fill = EF46)) +
geom_bar(position = "fill") +
coord_flip()
library(stringr)
ggplot(yy, aes(x = EF310, fill = EF46)) +
geom_bar(position = "fill") +
scale_x_discrete(labels = function(x) str_wrap(x, width = 25)) +
coord_flip()
library(scales)
ggplot(yy, aes(x = EF310, fill = EF46)) +
geom_bar(position = "fill") +
ylab("proportion") +
scale_x_discrete(labels = function(x) str_wrap(x, width = 25)) +
scale_y_continuous(labels = percent) +
coord_flip()
ggplot(yy, aes(x = EF310, fill = EF46)) +
geom_bar(position = "fill") +
ylab("proportion") +
scale_x_discrete(labels = function(x) str_wrap(x, width = 25)) +
scale_y_continuous(labels = percent) +
scale_fill_manual(values = c("männlich"="midnightblue",
"weiblich"="deeppink4")) +
coord_flip()
1. the variable E49 in the mz data set contains the information of the about the marital status
ggplot(yy,aes(x = EF310, fill = EF46)) +
geom_bar(position = position_dodge(), alpha = 0.4) +
scale_x_discrete(labels = 1:8) +
scale_fill_manual(values = c("männlich" = "midnightblue",
"weiblich" = "deeppink3")) +
ylab("Anzahl Personen") +
xlab("hoechster Schulabschluss") +
ggtitle("Barplot")
library(ggthemes)
ggplot(yy,aes(x = EF310, fill = EF46)) +
geom_bar(position = position_fill(),colour="black") +
scale_x_discrete(labels = 1:8) +
## scale_fill_grey() +
ylab("Anzahl Personen") +
xlab("hoechster Schulabschluss") +
ggtitle("Barplot") +
facet_wrap(~EF49,nrow = 2) +
theme_stata()