Skip to content

Instantly share code, notes, and snippets.

Avatar
🏄‍♂️

Luís Cruz luiscruz

🏄‍♂️
View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am luiscruz on github.
  • I am luiscruz (https://keybase.io/luiscruz) on keybase.
  • I have a public key whose fingerprint is FA17 CC97 F92D CD26 E1AD F396 41B1 395B CEDD C3EA

To claim this, I am signing this object:

@luiscruz
luiscruz / facet_wrap.r
Created Feb 10, 2016
Use facet_wrap to compare a variable (friend_count) distribution according to the value of another variable (gender)
View facet_wrap.r
library(ggplot2)
pf <- read.delim("https://s3.amazonaws.com/udacity-hosted-downloads/ud651/pseudo_facebook.tsv")
qplot(data=subset(pf, !is.na(gender)), x=friend_count, binwidth=25)+
scale_x_continuous(limits = c(0,1000), breaks=seq(0,1000,50))+
facet_wrap(~gender)
@luiscruz
luiscruz / freqpoly.r
Created Feb 10, 2016
Frequency Polygon with different scales
View freqpoly.r
library(gridExtra)
library(ggplot2)
pf <- read.delim("https://s3.amazonaws.com/udacity-hosted-downloads/ud651/pseudo_facebook.tsv")
p1<-qplot(data=pf, x=friend_count, binwidth=30)
p2<-qplot(data=pf, x=log10(friend_count+1))
p3<-qplot(data=pf, x=sqrt(friend_count))
grid.arrange(p1,p2,p3,ncol=1)
@luiscruz
luiscruz / dplyr_to_group_by_ggplot.r
Created Feb 10, 2016
Create group_by data frame using dplyr; use grid to show 2 plots in the same figure
View dplyr_to_group_by_ggplot.r
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),
View ggplot_scatter_with_mean.r
pf <- read.delim("https://s3.amazonaws.com/udacity-hosted-downloads/ud651/pseudo_facebook.tsv")
ggplot(aes(x=age, y=friend_count), data=pf)+
xlim(13,90)+
geom_point(alpha = 0.05,
position = position_jitter(h=0),
color = 'blue'
)+
coord_trans(y="sqrt")+
geom_line(stat="summary", fun.y = mean)