Created
January 19, 2019 19:05
-
-
Save kjhealy/02eb16d8596c99354301231494367be2 to your computer and use it in GitHub Desktop.
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
## Start with the code in https://github.com/kjhealy/lexis_surface/blob/master/lexis.r | |
## At the bottom, the `fra_surface` object is done in 3D with the `plotly` library. We can | |
## also do it with `rayshade`: | |
library(rayshader) | |
## rayshade wants the axes a little differently from plotly | |
## but like plotly it wants a matrix. | |
fra_surf <- fra_surf[c(1:201),c(100:1)] | |
raymat <- ray_shade(as.matrix(fra_surf), lambert = TRUE) | |
ambmat <- ambient_shade(as.matrix(fra_surf)) | |
fra_surf %>% as.matrix() %>% | |
sphere_shade(sunangle = 45, texture = create_texture("#440154FF", "#3B528BFF", "#21908CFF", "#5DC863FF", "#FDE725FF")) %>% | |
add_shadow(raymat, 0.7) %>% | |
add_shadow(ambmat, 0.7) %>% | |
plot_3d(as.matrix(fra_surf), | |
fov=0, theta=125, zoom=1, phi=35, | |
zscale = 4, | |
windowsize = c(3000,3000)) | |
## NB x and y values for the labels are piced out using | |
## the row and column indexes of the elevation matrix, | |
## not the values of the years and ages (though for ages | |
## it's the same as the column index). | |
render_label(as.matrix(fra_surf),x=54, y=25, z=240, zscale=4, | |
text = "Smallpox", textsize = 1, linewidth = 2) | |
render_label(as.matrix(fra_surf),x=102, y=25, z=250, zscale=4, | |
text = "Influenza Epidemic", textsize = 1, linewidth = 2) | |
render_label(as.matrix(fra_surf),x=128,y=25, z=250, zscale=4, | |
text = "World War II", textsize = 1, linewidth = 2) | |
render_label(as.matrix(fra_surf),x=150,y=2, z=150, zscale=4, | |
text = "Declining Infant Mortality", textsize = 1, linewidth = 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment