tylermorganwall / rayshader

R Package for 2D and 3D mapping and data visualization
https://www.rayshader.com/
2.06k stars 214 forks source link

Request: could you let the rayshader apply to ggtern map #187

Closed pangxueyu233 closed 2 years ago

pangxueyu233 commented 3 years ago

Hi, it's really a beautiful package. And we really like to use it in our reseach visualization. however, we found the rayshader cannot be applied to used in ggtern results, here is my code,

library(ggtern)
labFnc <- function(x,digits=2) format(round(unique(x),digits),digits=digits)
mydata <- data.frame(
  x = runif(50, min = 0.25, max = 12),
  y = runif(50, min = 0.1, max = 10),
  z = runif(50, min = 0.5, max = 4),
  value = runif(50, min = 10000, max = 20000))

plot <- ggtern(data = mydata,aes(x = x, y = y, z = z,col=value)) + 
  theme_bw() +
  geom_point(alpha = 0.8, size = 3) +
  theme_showarrows() +
  scale_T_continuous(breaks=unique(mydata$x),labels=labFnc(mydata$x))+ 
  scale_L_continuous(breaks=unique(mydata$y),labels=labFnc(mydata$y))+ 
  scale_R_continuous(breaks=unique(mydata$z),labels=labFnc(mydata$z))

plot 

image

But we executed the rayshader codes as following:

library(rayshader)
plot_gg(plot, width = 10, raytrace = TRUE, preview = TRUE)

it report the error:

Error: CoordTern requires the following missing aesthetics (tlr->xy) : z

Could you help us work it out ?

Thanks

tylermorganwall commented 2 years ago

You can create your own height mapping by passing in a separate list—see this gist for an example:

https://gist.github.com/tylermorganwall/9dc6bc30a26a4e0465f16cdf2c3fbb88