Created
June 27, 2019 22:42
-
-
Save jebyrnes/f3f626aa24f565d78003f05aab4d0372 to your computer and use it in GitHub Desktop.
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
| #Rayshader reprex to try and put a flat raster map under a | |
| #set of 3d points | |
| library(rayshader) | |
| library(ggplot2) | |
| library(dplyr) | |
| library(maps) | |
| library(ggmap) | |
| data(world.cities) | |
| japan <- world.cities %>% filter(country.etc == "Japan") %>% | |
| filter(pop > 1e6) | |
| japan_map <- get_stamenmap(bbox = c(left = min(japan$long), | |
| bottom = min(japan$lat), | |
| right = max(japan$long)+3, | |
| top = max(japan$lat)+3), | |
| maptype = "watercolor", | |
| zoom = 5) | |
| #plot together | |
| together_plot <- ggmap(japan_map) + | |
| geom_point(data = japan, | |
| aes(x = long, y = lat, color = pop)) + | |
| scale_color_viridis_c(option = "C") | |
| #Separate plots | |
| map_plot <- ggmap(japan_map) | |
| point_plot <- ggplot() + | |
| geom_point(data = japan, | |
| aes(x = long, y = lat, color = pop)) + | |
| scale_color_viridis_c(option = "C") | |
| #together | |
| plot_gg(together_plot,multicore=TRUE, | |
| width=4, | |
| height=4, | |
| scale=250, | |
| windowsize = c(1000,800)) | |
| render_camera(zoom = 0.5, theta = 130, phi = 35) | |
| render_snapshot("together.png") | |
| #Apart | |
| plot_gg(list(map_plot, point_plot),multicore=TRUE, | |
| width=4, | |
| height=4, | |
| scale=250, | |
| windowsize = c(1000,800)) | |
| render_camera(zoom = 0.5, theta = 130, phi = 35) | |
| render_snapshot("apart.png") | |
| #apart2 | |
| plot_gg(list(point_plot, map_plot),multicore=TRUE, | |
| width=4, | |
| height=4, | |
| scale=250, | |
| windowsize = c(1000,800)) | |
| render_camera(zoom = 0.5, theta = 130, phi = 35) | |
| render_snapshot("apart2.png") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice example @tylermorganwall .
I've been trying to plot a similar image with a slightly different approach: instead of showing geom_points() as "bars" in the 3d plot, I'm trying to use floating points. Do you have any thoughts on how I can do it?
