I am trying to replicate the example shown here, made with rayshader
package:
https://www.rayshader.com/reference/plot_gg.html
I was focused in particular on the histogram. Below I report the code:
library(ggplot2)
library(viridis)
library(rayshader)
library(tidyverse)
mtplot <- ggplot(mtcars) +
geom_point(aes(x=mpg,y=disp,color=cyl)) +
scale_color_continuous(limits=c(0,8))
mtplot
plot1 <- plot_gg(mtplot, width=3.5, sunangle=225, preview = TRUE)
plot2 <- plot_gg(mtplot, width=3.5, multicore = TRUE, windowsize = c(1400,866), sunangle=225,
zoom = 0.60, phi = 30, theta = 45)
render_snapshot(clear = TRUE)
My first problem is when I try to make plot1 and plot2 that I get the following error:
Error in hillshade[, , 1] * scales::rescale(shadowmap, c(max_darken, 1)) :
arrays incompatible
I would like to understand why and if it is possible to fix tis error.
My second question is, in case of work, how to export the image generated from plot1
and plot2
? I tried with other examples with ggsave()
but it is not working. Is there any other way?
Thank you in advance for every support.
Simply try again with the latest version from the master
branch on GitHub. It seems like the issue has been noticed and resolved a while ago (see #176), but the necessary changes are not yet on CRAN.
## if package is missing, run `install.packages("remotes")` first
remotes::install_github(
"tylermorganwall/rayshader"
)
library(rayshader)
library(ggplot2)
For saving the two plots, you can use the built-in PNG graphics device for preview = TRUE
(you will probably want to change from tempfile()
to something more permanent):
ofl1 = tempfile(fileext = ".png")
png(ofl1, width = 12, height = 8, units = "cm", res = 300)
plot1 = plot_gg(
mtplot
, width = 3.5
, sunangle = 225
, preview = TRUE
)
dev.off()
As for preview = FALSE
(default), use render_snapshot()
like this:
plot2 = plot_gg(
mtplot
, width = 3.5
, multicore = TRUE
, windowsize = c(1400, 866)
, sunangle = 225
, zoom = 0.60
, phi = 30
, theta = 45
)
ofl2 = tempfile(fileext = ".png")
render_snapshot(
filename = ofl2
, clear = TRUE
)