Created
May 9, 2019 14:42
-
-
Save lejarx/9e12dcbac278dccaaaa8b165ac894800 to your computer and use it in GitHub Desktop.
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
nobs <- 4000 | |
pb <- round(runif(n=1, min=0.1, max=0.8),1) | |
August <- rbinom(n=nobs, size=1, prob=pb) | |
pb <- round(runif(n=1, min=0.1, max=0.8),1) | |
September <- rbinom(n=nobs, size=1, prob=pb) | |
pb <- round(runif(n=1, min=0.1, max=0.8),1) | |
October <- rbinom(n=nobs, size=1, prob=pb) | |
pb <- round(runif(n=1, min=0.1, max=0.8),1) | |
November <- rbinom(n=nobs, size=1, prob=pb) | |
pb <- round(runif(n=1, min=0.1, max=0.8),1) | |
December <- rbinom(n=nobs, size=1, prob=pb) | |
#generate random id | |
myFun <- function(n = nobs) { | |
a <- do.call(paste0, replicate(5, sample(LETTERS, n, TRUE), FALSE)) | |
paste0(a, sprintf("%04d", sample(9999, n, TRUE)), sample(LETTERS, n, TRUE)) | |
} | |
round(runif(n=1, min=200000, max=300000),1) | |
AumPre <- log(runif(nobs, min=100000, max=250000)) | |
AumAft <- log(runif(nobs, min=100000, max=250000)) | |
AumIncrease <- as.integer(AumAft > AumPre) + 1 | |
table(AumIncrease) | |
ID <- myFun() | |
df <- data.frame(ID | |
, August | |
, September | |
, October | |
, November | |
, December | |
, AumPre | |
, AumAft | |
, AumIncrease) | |
str(df) | |
#NA replacement | |
df[is.na(df)] <- 0 | |
df %>% select(ID, AumPre, AumAft, AumIncrease | |
, August | |
, September | |
, October | |
, November | |
, December) -> df | |
upset(df, keep.order = T, | |
sets = c("August" | |
, "September" | |
, "October" | |
, "November" | |
, "December"),boxplot.summary = c("AumAft")) | |
colnames(df) | |
summary(df) | |
nrow(df) | |
movies <- read.csv( system.file("extdata", "movies.csv", package = "UpSetR"), header=T, sep=";" ) | |
df$x <- log(rep(x = movies$Watches+10,2)[1:nrow(df)]) | |
df$y <- log(rep(x = movies$AvgRating+10,2)[1:nrow(df)]) | |
upset(df | |
, sets = c("August" | |
, "September" | |
, "October" | |
, "November" | |
, "December") | |
, query.legend = "bottom" | |
, number.angles = 30 | |
, point.size = 3.5 | |
, line.size = 2 | |
, sets.x.label = "Total Participants" | |
, queries = list( | |
list( | |
query = elements, | |
params = list("AumIncrease", 1), | |
color = "red", | |
active = F | |
) | |
,list( | |
query = elements, | |
params = list("AumIncrease", 2), | |
color = "green", | |
active = F | |
) | |
) | |
) | |
colnames(df) | |
upset(df | |
, attribute.plots = list(gridrows = 100, ncols = 1, | |
plots = list( | |
list(plot = histogram, x = "x",queries = F), | |
list(plot = scatter_plot, y = "AumAft", x = "AumPre", queries = T), | |
list(plot = scatter_plot, y = "x", x = "y", queries = T))) | |
, sets = c("August", "September", "October", "November", "December") | |
, queries = list( | |
list( | |
query = elements, | |
params = list("AumIncrease", 1), | |
color = "red", | |
active = F | |
) | |
,list( | |
query = elements, | |
params = list("AumIncrease", 2), | |
color = "green", | |
active = F | |
) | |
) | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment