Skip to content

Instantly share code, notes, and snippets.

@jwinternheimer
Created April 28, 2015 16:19
Show Gist options
  • Save jwinternheimer/1dbc45ad01a17bf1ddb1 to your computer and use it in GitHub Desktop.
Save jwinternheimer/1dbc45ad01a17bf1ddb1 to your computer and use it in GitHub Desktop.
Growth Exploration
library(data.table); library(dplyr); library(tidyr); library(plyr)
library(ggplot2); library(scales); library(grid); library(RColorBrewer)
##################################################
## Number of Profiles for Awesome Users
##################################################
## Import and Tidy Data
awesome_active_profiles <- read.table("~/Downloads/awesome_active_profiles.csv",sep=",",header=T)
names(awesome_active_profiles) <- c("user_id","active_profiles")
## Create Histogram of Number of Profiles Connected
awesome_profiles_hist <- ggplot(awesome_active_profiles,aes(x=active_profiles)) +
geom_histogram(binwidth=1,color="white",fill="black",alpha=0.6) +
labs(x="Profiles Connected", y="Users", title="Awesome Users Profiles Connected") +
scale_x_continuous(limits=c(0,15),breaks=seq(0,15,1)) +
theme(panel.grid.major=element_line(size=.25)) + theme(panel.grid.minor=element_blank()) +
theme(axis.ticks=element_blank()) + theme(panel.grid.major.x = element_blank(),panel.grid.minor.x = element_blank())
##################################################
## Breakdown of Profile Types
##################################################
## Import and Tidy Data
profile_types <- read.table("~/Downloads/profile_types.csv",sep=",",header=T)
names(profile_types) <- c("user_id","facebook_profiles","linkedin_profiles","twitter_profiles","total_profiles")
profile_types <- profile_types %>%
mutate(other_profiles = total_profiles - (facebook_profiles + linkedin_profiles + twitter_profiles))
## Gather Profile types and make bar chart
gathered_profiles <- profile_types %>%
gather(type,count,facebook_profiles:other_profiles)
total_profiles <- gathered_profiles %>%
filter(type != "total_profiles") %>%
group_by(type) %>%
summarise(total = sum(count)) %>%
mutate(prop = total/sum(total))
total_profiles$type <- revalue(total_profiles$type,c("facebook_profiles"="Facebook",
"linkedin_profiles"="Linkedin",
"twitter_profiles"="Twitter",
"total_profiles"="Total",
"other_profiles"="Other"))
## Bar Chart
profile_bar <- ggplot(total_profiles,aes(x=type,y=prop)) + geom_bar(stat="identity",alpha=0.6) +
geom_text(aes(label=round(prop,2)),vjust=-0.2) + labs(x="Profile_Type",y="Proportion of All Profiles") +
theme(panel.grid.major=element_line(size=.25)) + theme(panel.grid.minor=element_blank()) +
theme(axis.ticks=element_blank()) + theme(panel.grid.major.x = element_blank(),panel.grid.minor.x = element_blank())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment