Skip to content

Instantly share code, notes, and snippets.

@luiscruz
Created February 10, 2016 11:36
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 luiscruz/edd7fdc2f0a88994d37d to your computer and use it in GitHub Desktop.
Save luiscruz/edd7fdc2f0a88994d37d to your computer and use it in GitHub Desktop.
Create group_by data frame using dplyr; use grid to show 2 plots in the same figure
suppressMessages(library(dplyr))
library(gridExtra)
pf <- read.delim("https://s3.amazonaws.com/udacity-hosted-downloads/ud651/pseudo_facebook.tsv")
pf.fc_by_age_months <- pf %>%
group_by(age_with_months) %>%
summarise(
friend_count_mean=mean(friend_count),
friend_count_median=median(friend_count),
n=n()
)
p1 <- ggplot(data=pf.fc_by_age_months, aes(x=age_with_months, y=friend_count_mean))+
geom_line()+
geom_smooth()
p2 <- ggplot(data=pf, aes(x=age, y=friend_count))+
geom_line(stat='summary',fun.y=mean)+
ylab("Friend Count Mean")
grid.arrange(p1,p2)
@luiscruz
Copy link
Author

rplot01

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment