R Language ggplot2 visual analysis of user data Facebook

 

Original link: http://tecdat.cn/?p=5895

 

Reading user data Facebook 

 

getwd()## [1]“C:/ Users / HH / Desktop / R Data analyst”list.files()## [1]“07-tidy-data.pdf”“demystifying.R”## [3 ]“demystifyingR2_v3.html”“demystifyingR2_v3.Rmd”## [5]“EDA_Course_Materials.zip”“lesson3_student.html”## [7]“lesson3_student.rmd”“pseudo_facebook.tsv”## [9]“reddit.csv “”stateData.csv“## [11]”tidy-data.pdf“pf <-read.delim('pseudo_facebook.tsv')name(pf)## [1]”userid“”age“## [3 ]“dob_day”“dob_year”## [5]“dob_month”“gender”## [7]“tenure”“friend_count”## [9]“friendships_initiated”“likes”## [11]“likes_received”“mobile_likes “## [13]”mobile_likes_received“”www_likes“## [15]”www_likes_received“

 

Users histogram birthday 

 

library(ggplot2)qplot(x = dob_day,data = pf)+ scale_x_continuous(breaks = 1:31)##`stat_bin()`using`bins = 30`。用`binwidth`选择更好的价值。

 

 

qplot(x = dob_day,data = pf)+ scale_x_continuous(breaks = 1:31)+ facet_wrap(~dob_month,ncol = 3)##`stat_bin()`使用`bins = 30`。用`binwidth`选择更好的价值。

 

 

  

Number of friends

 

qplot(friend_count,data = pf)##`stat_bin()`使用`bins = 30`。用`binwidth`选择更好的价值。

 

  

qplot(friend_count,data = pf)+ scale_x_continuous(limits = c(0,1000))##`stat_bin()`使用`bins = 30`。用`binwidth`选择更好的值。##警告:删除了包含非有限值(stat_bin)的2951行。

 

  

The face of the number of friends

#你会添加什么代码来按性别创​​建直方图?#将它添加到下面的代码中.qplot(x = friend_count,data = pf,binwidth = 10)+ scale_x_continuous(limits = c(0,1000) ),break = seq(0,1000,50))+ facet_wrap(〜sex性)##警告:删除了包含非有限值(stat_bin)的2951行。

 

 

qplot(friend_count,data = subset(pf,!is.na(gender)),binwidth = 25)+ scale_x_continuous(limits = c(0,1000),breaks = seq(0,1000,50))+ facet_wrap(〜性别)##警告:删除了包含非有限值(stat_bin)的2949行。

 

 

table(pf $ gender)## ## female male ## 40254 58574by(pf $ friend_count,pf $ gender,summary)## pf $ gender:female ## Min。第一曲。中位数第3曲。最大。## 0 37 96 242 244 4923 ## --------------------------------------- - ---------------- ## pf $性别:男## Min。第一曲。中位数第3曲。最大。## 0 27 74 165 182 4917

 

Who has more friends: a man or a woman? 

 

qplot(x = tenure,data = pf,binwidth = 30,color = I('black'),fill = I('#099DD9'))##警告:删除了包含非有限值(stat_bin)的2行。

 

 

qplot(x = tenure / 365,data = pf,binwidth = .25,color = I('black'),fill = I('#F79420'))+ scale_x_continuous(breaks = seq(1,7,1), limits = c(0,7))##警告:删除了包含非有限值(stat_bin)的26行。

 

 

notes:

qplot(x = tenure / 365,data = pf,xlab ='使用FB的年数',ylab ='样本中的用户数',binwidth = .25,color = I('black'),fill = I(' #F79420'))+ scale_x_continuous(breaks = seq(1,7,1),limits = c(0,7))##警告:删除了包含非有限值(stat_bin)的26行。

 

 Age

 

qplot(x =年龄,数据= pf,xlab ='用户年龄',ylab ='用户数',binwidth = 1,color = I('black'),fill = I('#5760AB'))+ scale_x_continuous(断裂= SEQ(1,113,5))

 

 

 

 

 

Block diagram

 

 

 Adjust the code to a friend concerned about the number of users between 0 and 1000.

▍ Need help? contact us

 

Guess you like

Origin www.cnblogs.com/tecdat/p/11363104.html