Skip to content

Instantly share code, notes, and snippets.

View eliocamp's full-sized avatar

Elio Campitelli eliocamp

View GitHub Profile
@eliocamp
eliocamp / fail_analysis.md
Created May 6, 2024 02:47
Analysisi of werid target
library(targets)

meta_pattern <- tar_meta(son_files) 
meta_branches <- tar_meta(all_of(meta_pattern$children[[1]]))

Total number of branches:

@eliocamp
eliocamp / lasermouse.R
Created March 10, 2024 03:48
Move mouse with a laser pointer
library(Rvision)
X <- 1920
Y <- 1080
corners_screen <- matrix(c(0, Y,
X, Y,
X, 0,
0, 0),
ncol = 2, byrow = TRUE)
@eliocamp
eliocamp / balook.R
Created November 13, 2023 16:34
buenos aires look
library(ggplot2)
library(dplyr)
library(extrafont)
#
# extrafont::font_import("~/Downloads/")
CHANEWEI <- "Chalet-NewYorkNineteenEighty"
# Download data
url <- "https://apitransporte.buenosaires.gob.ar/ecobici/gbfs/stationInformation"
library(metR)
library(data.table)
library(ggplot2)
proj <- "+proj=lcc +lon_0=-60 +lat_1=-0 +lat_2=-40"
topo <- GetTopography(ConvertLongitude(-85),
330, lat.north = 14, lat.south = -58,
resolution = 2/60) |>
library(ggplot2)
library(units)
library(sf)
world <- rnaturalearth::ne_countries(returnclass = "sf", scale = 10) |>
st_transform(crs = "+proj=moll")
# Make a hexagonal grid
size <- 1000000
@eliocamp
eliocamp / rsync-progress.R
Created May 29, 2023 17:06
Monitor a download in progress and print a progress bar with speed and eta.
total <- 116653684*1024 # change your total dir size here
folder_size <- function() {
system('du -s "[folder]"', intern = TRUE) %>% # change your dest folder here
strsplit(split = "\t", fixed = TRUE) %>%
.[[1]] %>%
.[1] %>%
as.numeric()
}
@eliocamp
eliocamp / StatQuantileBin.R
Last active July 24, 2023 13:50
Percentogram (histogram with bins of equal number of observations)
# This is now available into ggpercentogram.
# https://github.com/eliocamp/ggpercentogram/
StatQuantileBin <- ggplot2::ggproto("StatQuantileBin", ggplot2::StatBin,
default_aes = ggplot2::aes(x = ggplot2::after_stat(density), y = ggplot2::after_stat(density), weight = 1),
compute_group = function(data, scales,
binwidth = NULL, bins = 30, breaks = NULL, trim = 0,
closed = c("right", "left"), pad = FALSE,
flipped_aes = FALSE,
# The following arguments are not used, but must
# be listed so parameters are computed correctly
@eliocamp
eliocamp / smooth2d.R
Last active August 10, 2022 16:57
Smooths a 2D field using Discrete Cosine Transform or SVD
#' Smooths a 2D field
#'
#' @param x,y Vector of x and y coordinates
#' @param value Vector of values
#' @param kx,ky Proportion of components to keep in the x and
#' y direction respectively. Lower values increased the smoothness.
#'
#' @examples
#' library(ggplot2)
#' # Creates a noisy version of the volcano dataset and applies the smooth
@eliocamp
eliocamp / save_plot_data.R
Last active June 24, 2022 21:18
Save a zip file with the data used to create each plot.
# Define the directory where to save the plot data
knitr::opts_chunk$set(plot_data_dir = "plot-data2")
save_plot_data <- function(plot, label = "plot", dir = NULL) {
# If the user didn't set up a dir explicitly, don't do anything
if (is.null(dir)) {
return(invisible(NULL))
}
if (!dir.exists(dir)) {
@eliocamp
eliocamp / mds.R
Last active May 6, 2021 19:46
MDS
library(magrittr)
library(ggplot2)
library(rgl)
library(plotly)
set.seed(42)
# Cantidad de puntos por grupos
N <- 20
# Localización de los grupos