statnmap / blog_tips Goto Github PK
View Code? Open in Web Editor NEWComments and complete R script files shared on the blog
License: GNU General Public License v3.0
Comments and complete R script files shared on the blog
License: GNU General Public License v3.0
Hello,
First of all thank you for creating blog tutorials. I tried the focal
method to correlate two rasters based on this (https://statnmap.com/2018-01-27-spatial-correlation-between-rasters/) . The rasters can be accessed from here https://app.box.com/s/8p725xqsn540cc80vtl6j5kwekym5l7k. How can I please solve this issue?
.
Thank you,
a = raster("~/a_rstr.tif")
b = raster("~/b_rstr.tif")
# Stack covariates
a_b_stack = stack(a,b)
names(a_b_stack) <- c("a", "b")
# Use the function on two rasters at the same time. We define a third raster (a_b_nb) that records the positions of values from 1 to ncell. focal will thus extract the positions for which we can get values of the two rasters (as they now have the same extent, origin and resolution).
a_b_nb = raster(a_b_stack, 1)
values(a_b_nb = 1:ncell(a_b_stack)
matrix_a_b= values(a_b_stack) # stack as raster
# Define a function
focal_cor = focal(
x = a_b_nb,
w = matrix(1, 5, 5),
fun = function(x, y = matrix_a_b){ # [MW]
cor(y[x, 1], y[x, 2], # [MW]
use = "na.or.complete")
},
filename = file.path("~/focal_cor.tif"),
overwrite = TRUE
)
focal_cor = raster("~focal_cor.tif")
plot(focal_cor)
# Get data for ggplot
focal_cor_dat = SDMSelect::gplot_data(focal_cor, maxpixels = 50000) %>%
mutate(variable = "Correlation") %>%
filter(!is.na(value))
# Plot
ggplot(focal_cor_dat) +
geom_tile(aes(x, y, fill = value)) +
scale_fill_gradient2("Corr",
low = "#d7191c",
mid = "#ffffbf",
high = "#1a9641",
midpoint = 0) +
# geom_polygon(data = Europe_border,
# aes(long, lat, group = group),
# fill = "white",
# colour = "grey20", size = 0.1) +
coord_quickmap(
xlim = range(focal_cor_dat$x),
ylim = range(focal_cor_dat$y)
) + xlab("") + ylab("")
A few days exploring VSCode possibilities after multiple years developing with RStudio
https://statnmap.com/2021-10-09-how-not-to-be-lost-with-vscode-when-coming-from-rstudio/
Hi there!
Thanks for the tips and the codefolding scripts!
I'm following this steps Enable code folding in bookdown and blogdown and also
Code folding with blogdown + Academic theme to reproduce it for several themes, including "academic", but cannot make it work. (The "academic" theme changed, and the provided example doesn't fit well)
It looks like I'm missing something or the code itself should be adjusted for each particular there.
Here are my attempts:
Any suggestion will be appreciated!
hugo_version()
[1] ‘0.66.0’
I made this question in stackoverflow about it any ideas on how to solve this?
https://stackoverflow.com/questions/74402263/error-adding-codefolding-in-blogdown-in-r
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.