Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shuozhang1985/737e80b24f62d71f7c3967f1c1b90459 to your computer and use it in GitHub Desktop.
Save shuozhang1985/737e80b24f62d71f7c3967f1c1b90459 to your computer and use it in GitHub Desktop.
app_data=read.csv('./data/appmap.csv', header=T, stringsAsFactors = F)
#str(app_data)
app_map=dplyr::filter(app_data, !is.na(longitude), !is.na(latitude), !is.na(group))%>%
dplyr::filter(longitude>=73, longitude<136, latitude>=4, latitude<54)
#str(app_map)
N1=nrow(app_map)
agegroup1=rep(0, N1)
for (i in 1:N1){
if (app_map$age[i]<=26){
agegroup1[i]='post-90s'
}
else if (app_map$age[i]>26&app_map$age[i]<=36){
agegroup1[i]='post-80s'
}
else if (app_map$age[i]>36&app_map$age[i]<=46){
agegroup1[i]='post-70s'
}
else if (app_map$age[i]>46&app_map$age[i]<=56){
agegroup1[i]='post-60s'
}
else if (app_map$age[i]>56){
agegroup1[i]='post-50s'
}
}
app_map=mutate(app_map, agegroup=agegroup1)
#unique(app_map$category)
agedis1=app_map%>%
dplyr::filter(category %in% c("Property Industry 2.0", "Industry tag" , "video" ,
"Services 1" ,"P2P net loan" ) ) %>%
dplyr::group_by(agegroup, category)%>%
summarise(n=n())%>%
mutate(percent=n/sum(n))
ageplot1=ggplot(data=agedis1, aes(x=agegroup, y=percent,
fill=category))+
geom_bar(stat = 'identity')+
xlab('age group')+
ylab('percent of number')+
ggtitle('User Age Group Distribution of APP cateogoreis')+
theme_bw()
ggplotly(ageplot1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment