Created
August 4, 2020 13:14
-
-
Save tylermorganwall/6397f160e4e587757199fe819b6cb040 to your computer and use it in GitHub Desktop.
Palmer Penguin Dataset, 3D ggplot
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(rayshader) | |
library(ggplot2) | |
library(palmerpenguins) | |
library(tidyverse) | |
library(rayrender) | |
library(rayimage) | |
library(magick) | |
penguins | |
penguins %>% | |
mutate(species = factor(species, levels = c("Chinstrap", "Gentoo", "Adelie"))) %>% | |
ggplot(aes(x = flipper_length_mm, y = body_mass_g, color = bill_depth_mm)) + | |
geom_point(size = 2) + | |
scale_color_viridis_c("Bill Depth (mm)") + | |
facet_wrap(~species) + | |
scale_x_continuous("Flipper Length (mm)") + | |
scale_y_continuous("Body Mass (g)") + | |
theme(strip.text = element_text(size=16)) -> | |
mass_flipper | |
plot_gg(mass_flipper, width = 8, height=4, windowsize = c(1000, 800), raytrace = FALSE, height_aes = "color", | |
zoom =1, phi = 45, theta = 30, sunangle = 225, soliddepth = -100, scale = 250, | |
max_error = 0.01, verbose=TRUE, shadow = FALSE, shadow_intensity = 0.5) | |
thetaval = 20 * sinpi(seq(0,360,length.out = 361)[-361]/180) | |
for(i in 90:270) { | |
render_camera(fov=70,theta=thetaval[i],zoom=0.8,phi=45) | |
render_highquality(light = FALSE, cache_filename = "penguins55", | |
scene_elements = | |
sphere(y = -20150, radius = 20000, angle = c(90,0,0), | |
material=rayrender::dielectric(attenuation = c(1,1,0.3)/6000)) %>% | |
add_object(xy_rect(z=-700,x=-250,y=1074/2*1-60,xwidth=1800*1.2,ywidth=1074*1.2, | |
material=diffuse(image_texture = "lter_penguins.png", | |
alpha_texture = "lter_penguins.png"))), | |
samples=300, sample_method = "stratified", filename= glue::glue("penguins{i}"), | |
camera_lookat = c(0,200,0), min_variance = 0, | |
environment_light = "winter_river_4k.hdr", #HDRI image from hdrihaven.com | |
rotate_env=180) | |
} | |
counter = 1 | |
for(i in seq(179,90,-1)) { | |
add_title(sprintf("penguins%d.png", i), filename = sprintf("penguins%d.png", counter)) | |
counter = counter + 1 | |
} | |
counter = 271 | |
for(i in seq(269,180,-1)) { | |
add_title(sprintf("penguins%d.png", i), filename = sprintf("penguins%d.png", counter)) | |
counter = counter + 1 | |
} | |
titlemat = matrix(0,56,1000) | |
add_title(titlemat, title_text = "Comparing Three Penguins: Flipper Length (mm) vs Body Mass (g) vs Bill Length (mm)", preview=TRUE, | |
title_bar_color = "#0f7375", title_color = "white", title_size=24,title_bar_alpha = 1, | |
filename = "toppen") | |
for(i in 1:360) { | |
image_read(c(sprintf("toppen.png"),sprintf("penguins%d.png", i))) %>% | |
image_append(stack=TRUE) %>% | |
image_write(sprintf("finalpenguin%d.png",i)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment