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 / 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 / new_aes.R
Last active June 16, 2023 09:07
A way to add multiple color or fill scales to a ggplot2 plot
# All this is implemented (plus bugfixes!) in the ggnewscale package:
# https://github.com/eliocamp/ggnewscale
# If you have any issues, I prefer it if you send them as issues here:
# https://github.com/eliocamp/ggnewscale/issues
#' Allows to add another scale
#'
#' @param new_aes character with the aesthetic for which new scales will be
#' created
#'
@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 / tweet_storm.R
Last active October 10, 2022 16:02
Example of posting a twitter thread from R
---
title: "Tweet thread"
author: "Elio Campitelli"
output: github_document
---
```{r}
knitr::opts_chunk$set(dev = "png",
tweet_this = TRUE)
@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