This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("tidyverse") | |
library("stringr") | |
library("leaflet") | |
library("leaflet.extras") | |
library("sf") | |
# 日本地図のデータ | |
# https://oku.edu.mie-u.ac.jp/~okumura/stat/shape.html | |
japanmap <- read_sf("https://okumuralab.org/~okumura/stat/data/japan.geojson") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("numbers") # to use "isPrime" function | |
# Prepare dates | |
year <- 1000:2999 | |
nyeve <- as.integer(paste0(year, "1231")) | |
ny <- as.integer(paste0(year + 1, "0101")) | |
# Output | |
bool_successive <- isPrime(nyeve) & isPrime(ny) | |
cat(paste(nyeve[bool_successive], ny[bool_successive], sep = ", "), sep = "\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hexGrob <- function(x, y, size = rep(1, length(x)), gp = gpar()) { | |
stopifnot(length(y) == length(x)) | |
n <- length(x) | |
dx <- resolution(x, FALSE) | |
dy <- resolution(y, FALSE) | |
if(dx == 1) dx <- dy | |
if(dy == 1) dy <- dx | |
dratio <- dy/dx | |
grid::polygonGrob(rep.int(cos(pi/2 + pi/3 * 0:5)*dx/sqrt(3), n) + | |
rep(x + y/2/dratio, each = 6), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(!require("sf")){ | |
install.packages("sf") | |
library("sf") | |
} | |
hex_sf <- function(x, y, radius = 1){ | |
stopifnot(length(y) == length(x) && | |
is.integer(x) && is.integer(y)) | |
center_x <- sqrt(3) * radius * x + | |
sqrt(3) / 2 * radius * y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The current stable version of {car} package (Ver. 3.0-0) does not output scatterplots properly. | |
# Instead, use the development version as following: | |
# install.packages("car", repos="http://R-Forge.R-project.org") | |
car::scatterplot(Sepal.Length ~ Petal.Width | Species, | |
data = iris, | |
boxplots= "xy", xlab="", ylab="", | |
grid = FALSE, legend = FALSE, | |
col = "black", | |
regLine = FALSE, smooth = FALSE) |