I'm trying to create an stl file based on a US map with different locations, as points, at different heights based on a data value.
I can create the points part relatively easily.
library(ggplot2)
library(data.table)
library(rayshader)
myPoints <- structure(list(N = c(7.34e+20, 1e+18, 1.471e+21, 1.35e+21, 2.096e+21
), latitude = c(35.060137, 42.151816, 34.420986, 39.713209, 32.445652
), longitude = c(-93.133718, -71.77203, -92.530547, -75.661478,
-93.739031)), row.names = c(NA, -5L),
class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x0000000006431ef0>)
gg1 <- ggplot() +
geom_map(data = us, map = us, aes(x = long, y = lat, map_id = region),
fill = "#ffffff", color = "#ffffff", size = 0.15) +
geom_point(data = test, aes(x = longitude, y = latitude, color = N), inherit.aes = F) +
theme(legend.position = "none")
gg1
plot_gg(gg1, multicore = TRUE, width = 5, height = 5, scale = 250, windowsize = c(1400,866),
zoom = 0.55, phi = 30)
But, when I save to an stl using rayshader, the US portion is flat.
In other words, it is basically a flat surface with some spikes coming up. So I thought I would try to just add in some state level data, based off here , and that would add some elevation to the US portion.
But what happens is the elevated US portion wipes out the point data.
us <- map_data("state")
arr <- USArrests %>%
rownames_to_column("region") %>%
mutate(region = tolower(region))
arr$Murder <- 0.01
gg2 <- ggplot() +
geom_map(data = us, map = us, aes(x = long, y = lat, map_id = region),
fill = "#ffffff", color = "#ffffff", size = 0.15) +
geom_map(data = arr, map = us, aes(fill = Murder, map_id = region), color = "#ffffff") +
geom_point(data = test, aes(x = longitude, y = latitude, color = N), inherit.aes = F) +
theme(legend.position = "none")
gg2
plot_gg(gg2, multicore = TRUE, width = 5, height = 5, scale = 250, windowsize = c(1400,866),
zoom = 0.55, phi = 30)
Ultimatly what I would like is the US portion slightly elevated, and then my point data above that. I tried mulitply the points to make even large, etc, but I can't get it.
I am wondering if I need to forgo the rayshader ggplot function, and try to use a matrix, but I'm still learning to work with spatial data I don't know a good way to convert US map data to a matrix and correctly label the points on said matrix.
I'm open to any and all suggestions.