Created
October 14, 2020 21:13
-
-
Save djnavarro/d565ca2304974db3ecc8741b5e318e4e to your computer and use it in GitHub Desktop.
computes floating point errors
This file contains hidden or 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(ggplot2) | |
library(dplyr) | |
library(paletteer) | |
# specify the range | |
lo <- 0 | |
hi <- 4 | |
by <- .01 | |
# create data structure | |
val <- seq(lo, hi, by) | |
dat <- expand.grid( | |
x = val, | |
y = val, | |
z = seq(lo, 2*hi, by) | |
) | |
dat <- dat %>% | |
mutate(s = x + y - z) %>% # compute all sums | |
filter(abs(s) < by/10) %>% # retain ostensibly zero rows | |
arrange(x, y) # be pretty | |
# create plot object | |
pic <- ggplot(dat, aes(x, y, fill = s)) + | |
geom_raster(show.legend = FALSE) + | |
theme_void() + | |
coord_fixed() + | |
scale_fill_paletteer_c("scico::broc") + | |
scale_x_continuous(expand = c(0, 0)) + | |
scale_y_continuous(expand = c(0, 0)) + | |
NULL | |
# draw plot | |
ggsave( | |
filename = here::here("image", "floating_point_01.png"), | |
plot = pic, | |
height = 5000/300, | |
width = 5000/300, | |
dpi = 300 | |
) |
Author
djnavarro
commented
Oct 14, 2020
This is so beautiful 😍 thanks for sharing it Danielle!
❤️
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment