{{ message }}

Instantly share code, notes, and snippets.

# Fumiaki Nishihara （西原史暁） fnshr

Created Dec 31, 2020
Find new year's days whose dates are prime numbers and whose previous dates are also prime numbers.
View find-prime-dates.R
 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")
Last active Jul 22, 2018
geom_ function for ggplot2 to create a hexagonal map
View geom_simpler_hex.R
 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),
Last active Jul 22, 2018
Create a hexagonal map as an sf object
View hex_sf.R
 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
Last active Jul 20, 2018
Create the scatterplot in the High School Course of Study Guide for Mathematics of Japan (2018)
View iris-scatterplot.R
 # 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)