Skip to content

Instantly share code, notes, and snippets.

View juanchiem's full-sized avatar
😳

Juan Edwards Molina juanchiem

😳
View GitHub Profile
# remotes::install_github("ropensci/gistr")
pacman::p_load(tidyverse, gistr)
options(github.username = 'juanchiem')
gists('mineall')
gist("3690306a2f7d7b36ac251fd55cf05e09") %>% gist_save() %>% gist_open()
# Get country centroids---
pacman::p_load(rgeos, rworldmap)
# get world map
wmap <- getMap(resolution="low")
@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) +
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)) %>%
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.
# 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)
dat <- tibble(
x_1 = runif(10),
x_2 = runif(10),
x_3 = runif(10)
)
dat |>
mutate(
across(
.cols = everything(),
.fns = rank,
# 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))
```{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
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))
@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))+