Created
February 10, 2016 11:36
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Author
luiscruz
commented
Feb 10, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment