Skip to content

Commit

Permalink
Graficas
Browse files Browse the repository at this point in the history
  • Loading branch information
mvilchis committed Oct 26, 2016
1 parent 55b0514 commit 4740b49
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tarea6/grafs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
library(dplyr)
library(ggplot2)

source("utils.R")

datos_cat <- read_psv("out_cat.psv")

datos_part <- read_psv("out_part.psv")

#Grafica catalan
#Tiempo
datos_cat %>%
ggplot() +
geom_point(aes(n, tiempo), alpha = 0.6) +
theme_bw() +
scale_colour_continuous(low = "grey", high = "black", na.value = "white")
#Llamadas a funcion
datos_cat %>%
ggplot() +
geom_point(aes(n,llamadas), alpha = 0.6) +
theme_bw() +
scale_colour_continuous(low = "grey", high = "black", na.value = "white")


#Grafica de particion
#Tiempo
datos_part %>%
ggplot() +
geom_point(aes(n, m, size = tiempo, color = tiempo), alpha = 0.6) +
theme_bw() +
scale_colour_continuous(low = "grey", high = "black", na.value = "white")
#Llamadas a funcion
datos_part %>%
ggplot() +
geom_point(aes(n, m, color = llamadas), alpha = 0.6) +
theme_bw() +
scale_colour_continuous(low = "grey", high = "black", na.value = "white")


rbind(
(data.frame(tiempo = datos_dp$tiempo) %>%
mutate(tipo = "PD")),
(data.frame(tiempo = datos_rec$tiempo) %>%
mutate(tipo = "Rec"))
) %>%
ggplot() +
geom_boxplot(aes(x = tipo, y = tiempo)) +
theme_bw()




100 changes: 100 additions & 0 deletions tarea6/utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
library(readr)

write_psv <- function(x, path, col_names = T){
readr::write_delim(x,
path = path,
delim = "|",
col_names = col_names)
}

read_psv <- function(file, col_names = T){
readr::read_delim(file = file,
delim = "|",
col_names = col_names)
}

read_tsv2 <- function(file, col_names = T){
readr::read_delim(file = file,
delim = "\t",
col_names = col_names)
}

read_csv3 <- function(file,
col_names = T,
col_types = NULL,
na = c("", "NA"),
comment = "",
skip = 0,
n_max = -1,
progress = interactive()){
readr::read_delim(file = file,
delim = ",",
quote = "\"",
col_names = col_names,
col_types = col_types,
na = na,
comment = comment,
skip = skip,
n_max = n_max,
progress = progress)
}


duplicated_2 <- function(vec){
# Shows ALL duplicated items
duplicated(vec) | duplicated(vec, fromLast=TRUE)
}


make_names <- function(vec) {
vec <- make.names(vec, unique = T)
vec <- iconv(vec, from = "utf-8", to = "ASCII//TRANSLIT")
vec <- stringi::stri_replace_all(regex = "[^a-zA-Z0-9\\_\\.]", replacement = "", str = vec)
vec <- stringi::stri_replace_all(fixed = ".", replacement = "_", str = vec)
return(vec)
}


axis_labels_vert <- function() theme(axis.text.x = element_text(angle = 90, hjust = 1))



outlier_range <- function(vec, na.rm = T){
min_vec <- min(vec, na.rm = na.rm)
max_vec <- max(vec, na.rm = na.rm)
cuarts <- quantile(vec, c(0.25, 0.75), na.rm = na.rm)
iqr <- as.numeric(cuarts[2] - cuarts[1])
range <- as.numeric(c(cuarts[1] - 1.5*iqr, cuarts[2] + 1.5*iqr))
range[1] <- ifelse(range[1] < min_vec, min_vec, range[1])
range[2] <- ifelse(range[1] > max_vec, max_vec, range[2])
return(range)
}





pretty_print <- function(num) {
num <- formatC(num, format="d", big.mark=',')
return(num)
}


print_object_sizes <- function(units = "Mb") {
objects <- ls(envir = globalenv())
tamanios <- lapply(objects, function(x){
format(object.size(get(x)), units = units)
}) %>% unlist()
df_out <- data.frame(object = objects,
size = as.numeric(substr(tamanios, 1, nchar(tamanios) - 3))) %>%
arrange(desc(size))
names(df_out) <- c("object", paste0("size (", units, ")"))
return(df_out)
}







0 comments on commit 4740b49

Please sign in to comment.