Skip to content

Instantly share code, notes, and snippets.

View juanchiem's full-sized avatar
😳

Juan Edwards Molina juanchiem

😳
View GitHub Profile
library(zoo)
browseURL("https://itsalocke.com/blog/understanding-rolling-calculations-in-r/")
dat <- read.csv("https://raw.githubusercontent.com/juanchiem/agro_data/master/hourly_weather.csv",
header = TRUE, sep = ";")
dat %>%
slice(1:48) %>%
mutate(tmean_12 = rollapply(temp,
width = 12, mean,
align = "right",
@juanchiem
juanchiem / coords.R
Last active September 14, 2022 22:51
library("tidyverse")
library("geometry")
data.frame(trap_degree = c(0,0,90,90),
distance_m = c(100, 200, 100, 200))%>%
mutate(data.frame(pol2cart(theta = trap_degree, r = distance_m))) %>%
ggplot()+
aes(x=y, y=x)+
geom_point() +
geom_text(aes(label=paste0(trap_degree,",", distance_m), vjust=1))+
library(purrr)
library(tidyverse)
newdata=data.frame(Sepal.Length=seq(4, 8, by=.5))
# newdata$Sepal.Length
fitted_models <- iris %>%
nest(data = -Species) %>%
mutate(fit = map(data, ~ lm(Petal.Length ~ Sepal.Length + I(Sepal.Length^2), data = .x)),
# fitted = map(fit, "fitted.values"),
predicted_Petal.Length= map(fit, ~ predict(.x, newdata = newdata))
```{r}
pacman::p_load(
tidyverse,
skimr, janitor,# exploracion de los datos
lme4, gamlss, # modelado
ggResidpanel, # diagnostico
DHARMa,
performance, # evaluar performance de los modelos
emmeans, # medias estimadas por el modelo
# the first argument gives expansion equal to its multiplication by limit range;
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
scale_x_continuous(limits = c(1, 7), expand = c(.1, 0))
# right position will be 7 + (7-1) * .1 = 7.6
# the second gives the absolute expansion added to both end of the axis:
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
scale_x_continuous(limits = c(1, 7), expand = c(0, 1))
dat <- tibble(
x_1 = runif(10),
x_2 = runif(10),
x_3 = runif(10)
)
dat |>
mutate(
across(
.cols = everything(),
.fns = rank,
# devtools::install_github('byzheng/weaana')
library(weaana)
file <- system.file("extdata/WeatherRecordsDemo1.met", package = "weaana")
# Read weather file - met file
met <- readWeatherRecords(file)
x_temp <- c(0, 26, 34)
y_temp <- c(0, 26, 0)
How to use R with SQLlite
================
This is a walkthrough of how you can use SQLite with R from my twitter
[@neilgcurrie](https://twitter.com/neilgcurrie).
Often in R we read in files of mixed formats. This gets messy fast and
when the data is too big R will lag or fall over. Enter the database.
SQLite is software used to interact with databases and is one of the
most popular engines around. We can work with SQLite directly from R.
library(tidyverse)
library(lubridate)
u <- "https://raw.githubusercontent.com/juanchiem/agro_data/master/weather_africa.csv"
sol <- rio::import(u)
sol %>% glimpse
sol %>%
mutate(date1= update(mdy(date), year = 1800)) %>%
@juanchiem
juanchiem / super-and-sub-script-labels.R
Created April 29, 2022 22:58 — forked from benmarwick/super-and-sub-script-labels.R
ggplot axis labels with superscript and subscript
AntroSO42<-read.csv("antroSO42-.csv", header = TRUE)
Bp <- AntroSO42[ ,(2:4), ]
library(tidyverse)
Bp %>%
gather(value, variable, -Class) %>%
ggplot(aes(Class,
variable)) +
geom_boxplot() +
facet_wrap( ~ value) +