Coder Social home page Coder Social logo

blog_tips's People

Contributors

statnmap avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

blog_tips's Issues

Blog focal method produces plot showing only bottom half of the study area

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("")

codefolding for other themes?

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’

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.