setwd("e:/Dropbox (Personal)/FSEGA/cursuri/2018-2019/R/cursuri")
pf <- read.csv('pseudo_facebook.tsv', sep='\t')
library(ggplot2)
options(repr.plot.width=5, repr.plot.height=3) # marimea graficului pentru afisarea pe ecran
qplot(x=friend_count, data=pf)
cu xlim() controlam ce portiune din axa este prezentata
qplot(x=friend_count, data=pf, xlim=c(1,1000))
qplot(x=friend_count, data=pf, xlim=c(500,1000))
qplot(x=friend_count, data=pf)+
scale_x_continuous(limits=c(500,1000))
etichete pentru axa x
qplot(x=friend_count, data=pf)+
scale_x_continuous(limits=c(500,1000), breaks=seq(0,1000,50))
separat in functie de valorile unei alte variabile
qplot(x=friend_count, data=subset(pf, !is.na(gender)))+
scale_x_continuous(limits=c(0,1000), breaks=seq(0,1000,250))+
facet_wrap(~gender, ncol=2)
qplot(x=friend_count, data=na.omit(pf))+
scale_x_continuous(limits=c(0,1000), breaks=seq(0,1000,250))+
facet_wrap(~gender, ncol=2)
na.omit() inlatura NA din toate variabilele...
table(pf$gender)
by(pf$friend_count, pf$gender, summary)
unde:
by(pf$friend_count, pf$gender, mean)
by(pf$friend_count, pf$gender, max)
Analizam variabila tenure - numar de zile de utilizare facebook
qplot(x=tenure, data=pf, color=I('black'), fill=I('#099009'))
Tenure este exprimat in zile: trecem la ani:
qplot(x=tenure/365, data=pf, color=I('black'), fill=I('#099009'))
qplot(x=tenure/365, data=pf, color=I('black'), fill=I('#099009'))+
xlab('un text potrivit pentru aceasta axa')+
ylab('aici trebuie obligatoriu o explicatie!')
qplot(x=age, data=pf, color=I('grey'), fill=I('grey'), binwidth=1)+
scale_x_continuous(limits=c(18,100), breaks=seq(20,100,10))
install.packages('gridExtra', repos = "http://cran.us.r-project.org")
library(gridExtra)
pregatim mai multe grafice
p1=qplot(pf$friend_count)
p2=qplot(pf$likes)
p3=qplot(pf$www_likes)
p4=qplot(pf$mobile_likes)
grid.arrange(p1,p2,p3,p4, ncol=2)
p8 <- ggplot(aes(x=friend_count), data=pf)+
geom_histogram()
p8
peste care putem sa adaugam diverse optiuni:
p9 <- p8+scale_x_sqrt()
p9
p10 <- p8+scale_x_log10()
p10
grid.arrange(p8,p9,p10, ncol=1)
p11 <- qplot(x=friend_count, data=subset(pf, !is.na(gender)), binwidth=10, geom='freqpoly')+
scale_x_continuous(lim=c(0,1000), breaks=seq(0,1000,100))
p11
separat in functie de gender
p12 <- qplot(x=friend_count, data=subset(pf, !is.na(gender)), binwidth=10, geom='freqpoly', color=gender)+
scale_x_continuous(lim=c(0,1000), breaks=seq(0,1000,100))
p12
p13 <- qplot(x=www_likes, data=subset(pf, !is.na(gender)), geom='freqpoly', color=gender)
p13
p13+scale_x_continuous(lim=c(0,2000))
by(pf$www_likes, pf$gender, summary)
by(pf$www_likes, pf$gender, sum)
qplot(x=gender, y=friend_count, data=subset(pf, !is.na(gender)), geom='boxplot')
reglarea axelor - Varianta 1
qplot(x=gender, y=friend_count, data=subset(pf, !is.na(gender)), geom='boxplot')+
scale_y_continuous(lim=c(0,1000))
reglarea axelor - Varianta 2
qplot(x=gender, y=friend_count, data=subset(pf, !is.na(gender)), geom='boxplot', ylim=c(0,1000))
qplot(x=gender, y=friend_count, data=subset(pf, !is.na(gender)), geom='boxplot')+
coord_cartesian(ylim=c(0,1000))
qplot(x=gender, y=friend_count, data=subset(pf, !is.na(gender)), geom='boxplot')+
coord_cartesian(ylim=c(0,260))
by(pf$friend_count, pf$gender, summary)