GithubHelp home page GithubHelp logo

rayshader's People

Contributors

boshek avatar hansthompson avatar jeroen avatar mikemahoney218 avatar robbibt avatar satrajit-chatterjee avatar tteo avatar tylermorganwall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rayshader's Issues

Follow up from - Confusing error message when plot_3d window is already open #19

I originally posted this here but the issue was closed so I was unsure if anybody saw my message.

@tylermorganwall I am receiving the same error as @nitschkematthew even though I ensure that the previously rendered 3D map window is closed.

I am using data around the Golden Gate Bridge from library(elevatr) with the same parameters you used to create Monterey Bay.

When rendering the 3D map I receive this error:

Error in if (heightmap1[i] < waterheight) { :                                                                                  
  missing value where TRUE/FALSE needed

Why is there no 3D base or white water line? Is that related to the error I'm getting? Also, the land looks different from your Monterey example. And the water has barely any relief at all. Still, there is more contrast in the Monterey Bay image than in the SF Bay image. I think I'm missing something.

screen shot 2019-01-12 at 12 20 32 am
screen shot 2019-01-12 at 12 17 43 am

# Elevation example - Golden Gate

library(magrittr)
library(rayshader)
library(elevatr)
library(sf)


# Create Simple Feature Geometry (sfg) Polygon around GG Bridge
gg_sfg <- st_polygon(list(cbind(c(-122.56, -122.56, -122.41, -122.41, -122.56), c(37.88, 37.77, 37.77, 37.88, 37.88))))

# Add projection info by creating an sfc object
gg_sfc <- st_sfc(gg_sfg, crs = "+init=epsg:4326")

# Create simple feature dataframe. Now can use with elevatr::get_elev_raster to get elevation data
gg_sf <- st_sf(gg_sfc)

# Get elevation data around the Golden Gate Bridge
elevation <- get_elev_raster(gg_sf, z = 13, src = "aws")
elmat2 = matrix(raster::extract(elevation, raster::extent(elevation), buffer = 10000), 
                nrow = ncol(elevation), ncol = nrow(elevation))

# Use same parameters as 3D Monterey Bay rendering
shadow = ray_shade(elmat2, zscale = 50, lambert = FALSE, multicore = TRUE)
amb = ambient_shade(elmat2, zscale = 50, multicore = TRUE)
elmat2 %>% 
  sphere_shade(zscale = 10, texture = "imhof1") %>% 
  add_shadow(shadow, 0.5) %>%
  add_shadow(amb) %>%
  plot_3d(elmat2, zscale = 50, fov = 0, theta = -20, phi = 45, windowsize = c(1000, 800), zoom = 0.75,
          water = TRUE, waterdepth = 0, wateralpha = 0.5, watercolor = "lightblue",
          waterlinecolor = "white", waterlinealpha = 0.3)


plot_gg fails with theme_void

Hello! Been trying to do some work with theme_void to void out (haha) axes and such, and keep getting the same error. Here's a reprex - and this works for other scales, too.

library(rayshader)
library(ggplot2)

a_plot <- ggplot(iris,
       aes(x = Sepal.Length, y = Sepal.Width, 
           color = Species)) +
  geom_point() + 
  theme_void() 

plot_gg(a_plot, multicore=TRUE,
          width=4,
          height=4,
          scale=250)

This produces

Error in (function (el, elname)  : 
  Element legend.box must be a string or numeric vector.

Installing rayshader with FreeType support

When I ran the render_label() example on the home page of the docs, I initially got an error unless I set freetype = FALSE:

render_label(montereybay,x=350,y=240, z=4000,zscale=50,
             text = "Moss Landing",textsize = 2,linewidth = 5)
# Error in rgl.texts(x = 350, y = 80.1314579963684, z = -240, text = "Moss Landing",  : 
# FreeType not supported in this build

The docs don't currently talk about how to enable FreeType support, but fishing around in this thread I guessed that I'd need to install the external dependency and then reinstall rgl from source.

I found and installed FreeType for Windows (hoping I have the right version!),as I'm on Windows 10, and then I reinstalled the rgl package from source (`install.packages('rgl', type = 'source')), which finished without error.

However, the same example now isn't rendering properly, even without the labels:

library(rayshader)
montshadow = ray_shade(montereybay,zscale=50,lambert=FALSE)
montamb = ambient_shade(montereybay,zscale=50)

montereybay %>% 
  sphere_shade(zscale=10,texture = "imhof1") %>% 
  add_shadow(montshadow,0.5) %>%
  add_shadow(montamb) %>%
  plot_3d(montereybay,zscale=50,fov=0,theta=-100,phi=30,windowsize=c(1000,800),zoom=0.6,
          water=TRUE, waterdepth = 0, waterlinecolor = "white", waterlinealpha = 0.5,
          wateralpha = 0.5,watercolor = "lightblue")
# Warning messages:
# 1: In rgl.material(...) : RGL: Pixmap load: file format unsupported
# 2: In rgl.material(...) : RGL: Pixmap load: failed
# 3: In rgl.material(...) : RGL: Pixmap load: file format unsupported
# 4: In rgl.material(...) : RGL: Pixmap load: failed

image

I might need to get rid of FreeType for Windows and strip rgl and rayshader to try again, but I was hoping you could update the docs to talk a bit more about enabling FreeType support 🙂

I'm using on R 3.5.0 on Windows 10 Pro 1809, along with rayshader 0.9.0 and rgl 0.99.16 (after reinstalling from source—not the version originally installed with rayshader).

Thanks!

Error in `add watermap`

Hi Tyler,

I ran into an interesting error trying to add a watermap created using the NHD to an elevation hillshade that I cant seem to fix (it appears it might be a bug). I have attached an example and the data I use can be found here

library(raster)
library(rgdal)
library(rayshader)

#Read in data
elev = raster("./rayshader_issue/elev.tif")
river = rgdal::readOGR("./rayshader_issue/nhd.shp")
#Convert NHD to SpatialLines
river = as(river, "SpatialLines")

# Create Raster with equal extent, dim and res to elev with all values = 0 
r = raster()
extent(r) = extent(elev)
dim(r) = dim(elev)
res(r) = res(elev)
crs(r) = crs(elev)
values(r) = 0

# Rasterize rivers to new raster;  set water to 1 and all else to 0
rr = rasterize(river, r)
values(rr)[is.na(values(rr))] = 0
values(rr)[values(rr) != 0] = 1

rr
elev
> rr
class       : RasterLayer 
dimensions  : 262, 336, 88032  (nrow, ncol, ncell)
resolution  : 0.0002777778, 0.0002777778  (x, y)
extent      : -104.8681, -104.7747, 38.7975, 38.87028  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=GRS80 +no_defs 
data source : in memory
names       : layer 
values      : 0, 1  (min, max)

> elev
class       : RasterLayer 
dimensions  : 262, 336, 88032  (nrow, ncol, ncell)
resolution  : 0.0002777778, 0.0002777778  (x, y)
extent      : -104.8681, -104.7747, 38.7975, 38.87028  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs 
data source : /Users/mikejohnson/Documents/GitHub/rayshader_issue/tyler/elev.tif 
names       : elev 
values      : 1773.827, 2000.999  (min, max)
# Convert water and elevation rasters to rayshader style matrix
water = matrix(raster::extract(rr,raster::extent(rr),buffer=1000),
               nrow=ncol(rr),ncol=nrow(rr))
elevmat = matrix(raster::extract(elev,raster::extent(elev),buffer=1000),
               nrow=ncol(elev),ncol=nrow(elev))

#check dims
dim(water) == dim(elevmat)
[1] TRUE TRUE
# Rayshade!!
sphere_shade(elevmat, texture = "imhof1") %>% 
add_water(water, color="desert") %>% 
plot_map()
Error in add_water(., water, color = "desert") :                                   
  `hillshade` and `watermap` dimensions must be the same; hillshade is 260x334, 
watermap is 262x336

Just to be sure:

dim(elevmat)
dim(water) 
> dim(elevmat)
[1] 336 262
> dim(water)
[1] 336 262

Have you found any way to avoid this / do you know were I am going wrong?

Thanks!

Mike

Colour not mapped to aesthetic clamped to max z

When I run the ggvolcano example code from rayshader.com, the contour lines are not draped over the volcano but clamped to the max Z value:

library(rayshader)
library(ggplot2)
library(reshape2)

ggvolcano = volcano %>% 
  melt() %>%
  ggplot() +
  geom_tile(aes(x = Var1, y = Var2, fill = value)) +
  geom_contour(aes(x = Var1, y = Var2, z = value), color='black') +
  scale_x_continuous("X", expand = c(0, 0)) +
  scale_y_continuous("Y", expand = c(0, 0)) +
  scale_fill_gradientn("Z", colours = terrain.colors(10)) +
  coord_fixed()

plot_gg(ggvolcano, width = 6, height = 4, raytrace=F, preview = F)

image

I can remedy this issue by forcing the contours to be a black color aesthetic by changing the geom_contour call to:

geom_contour(aes(x = Var1, y = Var2, z = value, color='foobar'),  color='black')

image

I have the same issue in other cases, for example when adding outlines in geom_tile calls, or unfilled polygons to a map.

Multi-threading?

I noticed that when rendering, rayshader seems to only use a single thread (or at least a single core). Is there a way, in the future, to support rendering with multiple cores? It would significantly speed up the workload for animations.

plot_gg issue

Today I installed
remotes::install_github("tylermorganwall/rayshader")
library(rayshader)
library(ggplot2)
library(sf)
library(viridis)

But still
could not find function "plot_gg"

any suggestion on that.

Thank You

Failed to install on R 3.5.0

I'm trying to install rayshader package on Windows 10 with R 3.5.0 via RStudio and it returns me a following error:

> devtools::install_github("tylermorganwall/rayshader")
Downloading GitHub repo tylermorganwall/rayshader@master
from URL https://api.github.com/repos/tylermorganwall/rayshader/zipball/master
Installation failed: Could not find build tools necessary to build rayshader

Even suggestions from Google don't work (e.g. this helpful issue). Have you got any ideas?

My session_info() if it may help:

Session info ----------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.5.0 (2018-04-23)
 system   x86_64, mingw32             
 ui       RStudio (1.1.423)           
 language (EN)                        
 collate  Russian_Russia.1251         
 tz       Europe/Moscow               
 date     2018-08-13 

Re-export pipe %>%

Hey Tyler,

Thanks for such an awesome package. I am trying to using as a base plotting option for some of my dissertation work!

One thing I discovered for one of my packages was to ability to re-export the magrittr pipe by adding a file like this.

It lets people use the pipe straight from your package without having to call library(magrittr).

Just a thought and thanks again!

Mike

error with make_base_cpp

installed the latest version from github, but it seems the make_base cpp export got lost in the latest update. Now when I try plot_3d(solid = TRUE) I get the error:

Error in make_base_cpp(heightmap1, heightmap2, heightmap3, heightmap4, :
object '_rayshader_make_base_cpp' not found

plot_3d() not working

I'm having trouble getting plot_3d to work correctly on Mac Mojave. I'm using this example from the demo.

options(rgl.useNULL = FALSE)

library(rayshader)

#Here, I load a map with the raster package.
loadzip = tempfile() 
download.file("https://tylermw.com/data/dem_01.tif.zip", loadzip)
localtif = raster::raster(unzip(loadzip, "dem_01.tif"))
unlink(loadzip)

#And convert it to a matrix:
elmat = matrix(raster::extract(localtif,raster::extent(localtif),buffer=1000),
               nrow=ncol(localtif),ncol=nrow(localtif))

ambmat = ambient_shade(elmat)

elmat %>%
  sphere_shade(texture = "desert") %>%
  add_water(detect_water(elmat), color="desert") %>%
  add_shadow(ray_shade(elmat,zscale=3,maxsearch = 300),0.5) %>%
  add_shadow(ambmat,0.5) %>%
  plot_3d(elmat,zscale=10,fov=0,theta=135,zoom=0.75,phi=45, windowsize = c(1000,800))
render_snapshot()

It produces a black square, either in RStudio or R opened from command line and if I try to save it instead of rendering it. My sessionInfo():

R version 3.5.2 (2018-12-20)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.4

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rayshader_0.10.2

loaded via a namespace (and not attached):
 [1] progress_1.2.0          xfun_0.6                remotes_2.0.2          
 [4] purrr_0.3.2             lattice_0.20-38         colorspace_1.4-1       
 [7] testthat_2.0.1          miniUI_0.1.1.1          usethis_1.4.0          
[10] htmltools_0.3.6         rlang_0.3.4             pkgbuild_1.0.2         
[13] manipulateWidget_0.10.0 later_0.8.0             glue_1.3.1             
[16] withr_2.1.2             sp_1.3-1                sessioninfo_1.1.1      
[19] jpeg_0.1-8              foreach_1.4.4           plyr_1.8.4             
[22] stringr_1.4.0           munsell_0.5.0           raster_2.8-19          
[25] htmlwidgets_1.3         devtools_2.0.1          codetools_0.2-15       
[28] memoise_1.1.0           knitr_1.22              callr_3.2.0            
[31] doParallel_1.0.14       httpuv_1.5.1            ps_1.3.0               
[34] crosstalk_1.0.0         parallel_3.5.2          curl_3.3               
[37] Rcpp_1.0.1              xtable_1.8-4            scales_1.0.0           
[40] backports_1.1.3         promises_1.0.1          desc_1.2.0             
[43] pkgload_1.0.2           webshot_0.5.1           jsonlite_1.6           
[46] mime_0.6                fs_1.2.6                hms_0.4.2              
[49] bmp_0.3                 png_0.1-7               digest_0.6.18          
[52] stringi_1.4.3           tiff_0.1-5              processx_3.3.0         
[55] shiny_1.3.2             grid_3.5.2              rprojroot_1.3-2        
[58] rgdal_1.3-6             cli_1.1.0               tools_3.5.2            
[61] magrittr_1.5            rgl_0.100.19            crayon_1.3.4           
[64] readbitmap_0.1.5        pkgconfig_2.0.2         prettyunits_1.0.2      
[67] imager_0.41.2           assertthat_0.2.1        iterators_1.0.10       
[70] R6_2.4.0                igraph_1.2.4.1          compiler_3.5.2 

I thought I might have been having problems with rgl, so I made sure these examples worked (https://cran.r-project.org/web/packages/rgl/vignettes/rgl.html), which did after I installed rgl with XQuartz open.

Any help is appreciated.

plot_3d error, detect_water issue

I have a tif file of a part of the Rift Valley in Kenya. I have put the tif file in a - Dropbox

There are 2 issues:

  • only 1 of the lakes is recognized (Lake Naivasha), 3 others aren't. I have put arrows at the two larger lakes. I have tried different options of detect_water, but was not successful in detecting all lakes.

selection_004

  • plot_map works, plot_3d function doesn't, give this error:
Error in if (argnameschar[2] == "montereybay" || (!is.na(argnameschar["heightmap"]) &&  : 
  missing value where TRUE/FALSE needed
Here is the code:

y = raster("./ASTGTM2_S01E036_dem.tif")
plot(y)

localtif = y
elmat = matrix(raster::extract(localtif,raster::extent(localtif),buffer=1000),
               nrow=ncol(localtif),ncol=nrow(localtif))

elmat %>%
  sphere_shade(texture = "desert") %>%
  add_water(detect_water(elmat), color="desert") %>%
  add_shadow(ray_shade(elmat)) -> zz

plot_map(zz)
plot_3d(zz)

Session info:

R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.5 LTS

Matrix products: default
BLAS: /usr/lib/openblas-base/libblas.so.3
LAPACK: /usr/lib/libopenblasp-r0.2.18.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=nl_NL.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=nl_NL.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=nl_NL.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] matlib_0.9.1    maditr_0.5.1    rayshader_0.5.0 sf_0.6-3        raster_2.6-7   
[6] sp_1.3-1       

Using SpatialPoints with render_label

I am trying to plot SpatialPoints with render_label, and I got a bit confused about the y-value in render_label, since I have to take the "opposite" of what I think it should be.

I hope this example illustrates my point:

library(sp)
library(raster)
library(rayshader)

## Get DEM Data and some random Points
poly <- Polygon(rbind(c(4488182, 2663172), c(4488182, 2669343),
                          c(4499991, 2669343), c(4499991, 2663172)))
poly <- Polygons(list(poly), 1);
poly <- SpatialPolygons(list(poly))
proj <- "+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000
+ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"
proj4string(poly) <- CRS(proj)
DEM_meter <- raster::getData("alt", country="AUT")
DEM <- projectRaster(DEM_meter, crs = CRS(proj))
DEM <- crop(x = DEM, extent(poly))
textlabls = spsample(poly, 10, type = "random");

## Convert DEM to matrix
DEM_matrix = t(as.matrix(DEM))

## Get x/y matrix coordinates from SpatialPoints
textlabls_df <- as.data.frame(sp::coordinates(textlabls))
raster_indic <- raster::cellFromXY(DEM, textlabls_df)
raster_x <- raster::colFromX(DEM, x = textlabls_df$x)
raster_y <- raster::rowFromY(DEM, y = textlabls_df$y)

I struggle with this next line, as without it the rayshader plot seems flipped although the z-values are all equal. If I remove this line, the 3d-plot looks ok, but I get different z-values, which feels weird.
raster_y = ncol(DEM_matrix) - raster_y + 1

## Get z-values of points
z_vals <- raster::extract(DEM, textlabls)
textlabls_df$z <- z_vals 

## Compare z-values
all.equal(textlabls_df$z[1],
          DEM_matrix[raster_indic[1]])
all.equal(DEM_matrix[raster_x[1],raster_y[1]],
          DEM_matrix[raster_indic[1]])

## Plot DEM and points
plot(DEM); points(textlabls$x,textlabls$y, pch=20)

## Plot with rayshader
shadow = ray_shade(DEM_matrix, zscale=200, lambert=FALSE)
amb = ambient_shade(DEM_matrix,zscale=200)
DEM_matrix %>%
  sphere_shade(zscale=200, texture = "imhof1") %>%
  add_shadow(shadow, 0.5) %>%
  add_shadow(amb) %>%
  plot_3d(DEM_matrix, zscale=200, zoom=0.8)
a <- lapply(1:length(raster_x), function(i) {
  render_label(DEM_matrix, x=raster_x[i], y=raster_y[i], z=textlabls_df$z[i], 
               freetype = FALSE, zscale=200, text = round(textlabls_df$z[i]))
})

Am I missing something, or are you still working on that function?

I noticed that the labels are placed in the cell centers. Is it or will it be possible to include exact coordinates instead of matrix indices?

And a little sidenote:
This raster to matrix transformation t(as.matrix(DEM)) is much faster, than the example in your Readme, although you loose the option to include a buffer or special function, etc. But in my cases, the results were always identical.
matrix(raster::extract(DEM,raster::extent(DEM),buffer=1000), nrow=ncol(DEM),ncol=nrow(DEM))

Can't install rayshader

I've tried installing rayshader on both windows and linux without success:

On Linux I get:

ERROR: configuration failed for package ‘av’

  • removing ‘/net/home/h05/hadnk/R/x86_64-pc-linux-gnu-library/3.6/av’
    Error in i.p(...) :
    (converted from warning) installation of package ‘av’ had non-zero exit status

On windows I get when trying to install from devtools:

devtools::install_github("tylermorganwall/rayshader")
Error in curl::curl_fetch_memory(url, handle = h) :
Timeout was reached: Connection timed out after 10000 milliseconds

By downlading zip and trying to install locally I get:

utils:::menuInstallLocal()
require(rayshader)
Loading required package: rayshader
Warning message:

In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called ‘rayshader’

color paramater of add_water does not accept hexcode

Help file for add_water says you can provide a " A hexcode or recognized color string." but this doesn't seem to work, returns error:

Error in color[i]/256 : non-numeric argument to binary operator.

Looking at the function, it appears it assigns a rgb to the variable color if you provide one of the palette names, but it doesn't check if you just provide a hexcode.

Allow NA for plot_3d

First, thank you for this really nice package.
I am playing with datasets along the coasts, which means there are some NA values for the area covered by the sea.
While using plot_3d, the following error message arises:

Error in if (any(hillshade > 1 || hillshade < 0)) { : 
  missing value where TRUE / FALSE is required

If I find some time, I'll go through you code to test if this is possible to allow missing values. For the moment, I thought I could at least open an issue with a reprex to not forget about it !

library(rayshader)
library(magrittr)

data("montereybay")

montereybay[1:100, 1:100] <- NA

#We use another one of rayshader's built-in textures:
montereybay_shadow <- montereybay %>%
  sphere_shade(texture = "desert") %>%
  add_water(detect_water(montereybay), color="desert") %>%
  add_shadow(ray_shade(montereybay)) %>%
  add_shadow(ambient_shade(montereybay))

montereybay_shadow %>% 
  plot_map()

montereybay_shadow %>%  
  plot_3d(montereybay)

request: set areal extent on cell edges in plot_map

In plot_map, raster is used to plot the rayshader matrix and sets the xmn/xmx, ymn/ymx equal to the first and last centre coordinates that are passed to rgl.surface.

This could offset the min and max values by 0.5 to be aligned to the data as represented by plot_3d, and it comes down to this code in plot_map:

raster::brick(array_from_mat, xmn = 0.5, 
                                                   xmx = dim(array_from_mat)[2] + 0.5,
                                                   ymn = 0.5, 
                                                   ymx = dim(array_from_mat)[1] + 0.5, ...)

Raster is based on an areal extent, and so setting the extent to the point coordinate is reducing the range by a half-cell on every side. It means that when adding the centre coordinates (1:ncol, 1:nrow) to the plot_map image they will fall properly in the centre.

m <- matrix(c(1:5, 5, 6:1), 3, 4)
l <- list(x = seq(1, nrow(m)), y = seq(1, ncol(m)), z = m)

r <- raster::raster(l)

library(raster)
library(rayshader)

plot_map(ambient_shade(t(as.matrix(r))))
## in master these don't fall correctly in the centre, with the half-cell mod they do
points(coordinates(r))

Please consider applying this change, it makes the two visual outputs (plot_map and plot_3d) easier to compare exactly (though it won't be noticed in normal usage considering how tiny the difference is - it will affect some careful examples that I am working on).

Thanks!

Facilitate use from RStudio

Thank you for this great package! I am excited about the potential use cases here.

One suggestion would be to set options to facilitate use from within RStudio by using WebGL instead of X11. This is essential and not just a nicety on RStudio Server since X11 is not available in that environment. It took me longer than I care to admit to figure that out. I think I would prefer this even on RStudio (desktop).

Thanks for considering.

Perspective support?

Sorry if I am just way off base here,, I don't mean to upset anyone, but it seems that all the rayshader images are rendered where there is no perspective control and parallel lines seem to diverge instead of converge in distance such as this video https://twitter.com/tylermorganwall/status/1118125396199903232 , can there be a feature so you can enable perspective with vanishing points?

Problem installing from github

Hi,

I have problems to install from CRAN and from gitHub

devtools::install_github("tylermorganwall/rayshader")

on Windows.

sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):
[1] Rcpp_1.0.1 pillar_1.4.1 compiler_3.6.0 prettyunits_1.0.2
[5] remotes_2.1.0 tools_3.6.0 digest_0.6.19 pkgbuild_1.0.3
[9] pkgload_1.0.2 memoise_1.1.0 tibble_2.1.3 gtable_0.3.0
[13] pkgconfig_2.0.2 rlang_0.4.0 cli_1.1.0 rstudioapi_0.10
[17] curl_3.3 withr_2.1.2 dplyr_0.8.1 desc_1.2.0
[21] fs_1.3.1 devtools_2.0.2 rprojroot_1.3-2 grid_3.6.0
[25] tidyselect_0.2.5 glue_1.3.1 R6_2.4.0 processx_3.3.1
[29] sessioninfo_1.1.1 ggplot2_3.2.0 callr_3.2.0 purrr_0.3.2
[33] magrittr_1.5 scales_1.0.0 backports_1.1.4 ps_1.3.0
[37] usethis_1.5.0 assertthat_0.2.1 colorspace_1.4-1 lazyeval_0.2.2
[41] munsell_0.5.0 crayon_1.3.4

I get the following error:

** testing if installed package can be loaded from temporary location
*** arch - i386
Error in library.dynam(dynlib, pkg, lib) :
DLL 'rgl' not found: maybe not installed for this architecture?
Error: package or namespace load failed for 'rayshader':
.onLoad failed in loadNamespace() for 'rgl', details:
call: NULL
error: Loading rgl's DLL failed.
Fehler: Laden fehlgeschlagen
Ausführung angehalten
*** arch - x64
ERROR: loading failed for 'i386'
removing 'C:/Users/User/Documents/R/win-library/3.6/rayshader'
Error: Failed to install 'rayshader' from GitHub:
(converted from warning) installation of package ‘C:/Users/User/AppData/Local/Temp/RtmpU5xJnF/file2c3017661e35/rayshader_0.11.0.tar.gz’ had non-zero exit status

I have installed rgl (0.100.24) and av( 0.2) but it doesnt fix the problem.

Thank you for your support in advance!
Javier

add_overlay: Error in `hillshade[, , 1] * (1 - overlay[, , 4])` : non-conformable arrays

I've searched for a fix for this, but I just can't seem to find one. The only related conversation was on Twitter and you said you fixed the issue in a commit around Dec 17, 2018 (which I thought might be this one).

I have been trying to debug, but my overlay image passes all the checks and is failing near the end (https://github.com/tylermorganwall/rayshader/blob/master/R/add_overlay.R#L122) and I can't figure out why. Below is my reproducible example.

I am using version 0.10.2

library(rayshader)

elev_file <- "sf-elevation.tif"
download.file("https://github.com/lindsayplatt/makerspace-sandbox/raw/master/rayshader/input/sf-elevation.tif",
              destfile = elev_file, mode = "wb")
elev_img <- raster::raster(elev_file)
elev_matrix <- matrix(
  raster::extract(elev_img, raster::extent(elev_img), buffer = 1000), 
  nrow = nrow(elev_img), ncol = ncol(elev_img)
)

img_file <- "overlay.png"
download.file("https://github.com/lindsayplatt/makerspace-sandbox/raw/master/rayshader/input/overlay.png",
              destfile = img_file, mode = "wb")
overlay_img <- png::readPNG(img_file)

# Without overlay works
elev_matrix %>%
  sphere_shade(texture = "imhof1") %>%
  plot_3d(elev_matrix)

# With overlay fails
elev_matrix %>%
  sphere_shade(texture = "imhof1") %>%
  add_overlay(overlay_img, alphalayer = 0.5) %>%
  plot_3d(elev_matrix)

Installation Problem

Sorry for the naive question, I'm totally new in R. When I'm installing the rayshader, I got wrong here:
Error in i.p(...) :
(converted from warning) installation of package ‘C:/Users/HAT_PI~1/AppData/Local/Temp/RtmpeiqxaI/file18bc520a116c/rayshader_0.5.1.tar.gz’ had non-zero exit status

Did I do anything wrong? Thank you!

ggplot2

Hi @tylermorganwall love watching the development of this package and very cool demos. I'm curious if you have a sense for when ggplot2 integration would be happening.
Thanks

Annotate using lat/long coordinates

Could you explain your workflow for determining the matrix indices used in the render_label examples?

render_label(montereybay,x=220,y=330,z=10000,zscale=50,text = "Santa Cruz")

It would be more natural for some applications to specify Santa Cruz for example by latitude=37,longitude=-122 rather than x=220,y=330.

Do you see a role in this package for helper functions to assist with that translation?

This was mentioned by @YsoSirius in #25 as well (who gave an example using raster's colFromX and colFromY), but I think this is deserving of its own issue.

The use case would be for placing labels by their lat/long coordinates, but also for other types of overlays such as a GPS track. Presumably some input data types such as GeoTIFF would have the necessary information to facilitate this.

Failed Mac install

> devtools::install_github("tylermorganwall/rayshader")
Downloading GitHub repo tylermorganwall/rayshader@master
from URL https://api.github.com/repos/tylermorganwall/rayshader/zipball/master
Installing rayshader
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL  \
'/private/var/folders/yh/q7331v716lbdvw4kjzl5m0g80000gp/T/RtmpNiBjr0/devtools1a7f7364f175/tylermorganwall-rayshader-c862fe1'  \
--library='/Library/Frameworks/R.framework/Versions/3.5/Resources/library' --install-tests 

* installing *source* package ‘rayshader’ ...
** libs
clang++  -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/progress/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c RcppExports.cpp -o RcppExports.o
clang++  -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/progress/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c calculate_normal.cpp -o calculate_normal.o
clang++  -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/progress/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c construct_matrix.cpp -o construct_matrix.o
clang++  -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/progress/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c find_groups.cpp -o find_groups.o
clang++  -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/progress/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c interpolate_color.cpp -o interpolate_color.o
interpolate_color.cpp:19:16: warning: expression result unused [-Wunused-value]
colormat[i,j] = bilinear_interp_colors(color_sw, color_nw, color_sw, color_nw,
                                       ^
                                         1 warning generated.
                                       clang++  -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/progress/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c lambshade.cpp -o lambshade.o
                                       clang++  -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/progress/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c rayshade.cpp -o rayshade.o
                                       clang++  -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/progress/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c rayshade_multicore.cpp -o rayshade_multicore.o
                                       clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o rayshader.so RcppExports.o calculate_normal.o construct_matrix.o find_groups.o interpolate_color.o lambshade.o rayshade.o rayshade_multicore.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
                                       installing to /Library/Frameworks/R.framework/Versions/3.5/Resources/library/rayshader/libs
                                       ** R
                                       ** byte-compile and prepare package for lazy loading
                                       Error in dyn.load(file, DLLpath = DLLpath, ...) : 
                                         unable to load shared object '/Library/Frameworks/R.framework/Versions/3.5/Resources/library/imager/libs/imager.so':
                                         dlopen(/Library/Frameworks/R.framework/Versions/3.5/Resources/library/imager/libs/imager.so, 6): Library not loaded: /opt/X11/lib/libX11.6.dylib
                                       Referenced from: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/imager/libs/imager.so
                                       Reason: image not found
                                       ERROR: lazy loading failed for package ‘rayshader’
                                       * removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rayshader’
                                       Installation failed: Command failed (1)

save_3dprint argument when rotate = "false" to print on the largest base

Since I've been playing with printing topography the past couple weeks and using your suggestion for rotate = "false" to improve resolution.

I've found that for printing coastal areas especially, the base is too narrow and creates some small wobbles as it prints up. Could we add an argument that will rotate to make the side with the highest mean or median elevations the base?

Rayshader not rendering

I was going through the sample code in the blog and ggplots render fine but when I run plot_gg this example takes about 2 minutes to show an RGL device box with a couple of intersecting lines on a white background, that's all. The warning messages are at the bottom. Hopefully it's just user error but let me know if I need to change something.
`
remotes::install_github("tylermorganwall/rayshader")

library(ggplot2)
library(readr)
library(viridis)
library(rayshader)

#=======================================

Example 1

gg <- ggplot(diamonds, aes(x, depth)) +
stat_density_2d(aes(fill = stat(nlevel)),
geom = "polygon",
n = 100,bins = 10,contour = TRUE) +
facet_wrap(clarity~.) +
scale_fill_viridis_c(option = "A")

plot_gg(gg,multicore=TRUE,width=5,height=5,scale=250)

sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server >= 2012 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] rayshader_0.11.0 viridis_0.5.1 viridisLite_0.3.0 readr_1.3.1 ggplot2_3.2.0
Warnings:Warning messages:
1: In rgl.surface(1:nrow(heightmap), -(1:ncol(heightmap)), heightmap[, :
RGL: GL Library : Maximum texture size of 1024x1024 exceeded.
(Perhaps enabling mipmapping could help.)
2: In rgl.primitive("triangles", x, y, z, normals, texcoords, ...) :
RGL: GL Library : Maximum texture size of 1024x1024 exceeded.
(Perhaps enabling mipmapping could help.)
3: In rgl.primitive("lines", x, y, z, ...) :
RGL: GL Library : Maximum texture size of 1024x1024 exceeded.
(Perhaps enabling mipmapping could help.)
4: In rgl.surface((-shadowwidth + 1):(rows + shadowwidth), -(-shadowwidth + :
RGL: GL Library : Maximum texture size of 1024x1024 exceeded.
(Perhaps enabling mipmapping could help.)`

sphere_shade and water issues

Hello guys,

First of all big, BIG thanks for this beautiful package ! Awesome work.

Almost everything works perfect in my tests, except for two functions that always throw error messages. As they are useful and major functions, this is quite annoying :

  • sphere_shade (although every other shading function works fine : ray_shade, lamb_shade, ambient_shade, so I guess my data/params are OK) which throws :

Error in temp[2:(nrow(temp) - 1), 2:(ncol(temp) - 1)] <- heightmap :
number of items to replace is not a multiple of replacement length

  • water=TRUE in plot_3d(...) which always results in :

Error in if (heightmap2[i] < waterheight) { :
missing value where TRUE/FALSE needed

Do you have any idea how to avoid these "crashes" ?

License Information?

Hello ✋ I could not find any information about the license that this software is released under. Perhaps a maintainer can help with this question?

Love the outputs of the program 👍

Raster to Matrix Transformation Error

Hi Tyler,

First of all, you have done really fantastic work. I'm an analyst with the Government of Alberta (it's one of the provinces of western Canada) and I do a lot of cartography and geomatics. I am very excited to use your work to produce some beautiful maps! After testing your code, it looks like there is a minor issue with creating the input matrix: the y-axis coordinates seem to be reversed. You can see it in the test data you have already used: if you compare your test data with a google map of the outlet of the Derwent River, you'll see what I mean.

I'm pretty new at R-based spatial analysis, but it seems this can be corrected before you use the sphere_shade() function by pre-rotating the matrix:

tif_file = raster::raster("dem_01.tif")
elmat = as.matrix(tif_file)
elmat = t(elmat)[,nrow(elmat):1]
elmat %>%
sphere_shade(texture = "desert") %>%
plot_map()

And produces this output, correctly orientated:
derwent_rotated

I'm sure you can find a more elegant solution, but for now, I hope this helps you improve your already fantastic work. It's great to find others with a passion for mapping and data visualization.

Warm regards,
Chris

detect_water swaps north/south vs. original matrix?

I was trying to use detect_water for feature engineering outside of the plotting workflow and I discovered a weird behavior. The latitude of the matrix produced by detect_water seems to swap north with south. You can see this by converting each matrix to a dataframe and plotting through ggplot. Perhaps the problem lies with they way I melt the matrix to a data frame but I use the same procedure for the water matrix and the original matrix.

This doesn't show up in the normal rayshader plotting workflow, obviously.

library(dplyr)
library(reshape2)
library(ggplot2)
library(rayshader)

# set below waterline points to zero so detect_water finds them
mont_depth <- montereybay
mont_depth[which(montereybay<0)] = 0
watermap <- detect_water(mont_depth)

# turn watermap matrix into a data frame
watermap_df <- watermap %>% 
  melt(value.name = "is_water") %>% 
  mutate(is_water = as.factor(is_water))

# turn original matrix into a data frame and merge with watermap
elev <- montereybay %>% 
  melt(value.name = "elev") %>%
  mutate(is_land = as.factor(ifelse(elev < 0 ,0,1))) %>% 
  full_join(watermap_df) %>% 
  as_tibble()
#> Joining, by = c("Var1", "Var2")

#illustrate that latitude for watermap is north/south swapped vs. original matrix
elev %>% 
  filter(elev < 0) %>% 
  ggplot() + 
  geom_tile(aes(Var1,Var2,fill=is_land),alpha=0.5) +
  geom_tile(data=watermap_df,aes(Var1,Var2,fill=is_water),alpha=0.8)

plot_3d() fails with missing data

I encountered a case where plot_3d() fails with missing values. It's the exact same code I used for this render: https://twitter.com/ClausWilke/status/1075423829491634177 only that I'm now looking at a different location in the same original raster tile.

crop_raster_square <- function(raster_input, lat, long, square_km, increase_resolution = 1){
  bounding_box <- sp::SpatialPoints(cbind(long, lat, square_km), proj4string = sp::CRS("+proj=longlat +datum=WGS84 +no_defs"))
  bounding_box <- sp::spTransform(bounding_box, sp::CRS("+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"))
  
  bounding_shape <- rgeos::gBuffer(bounding_box, width = bounding_box$square_km * 1000, quadsegs=1, capStyle="SQUARE")
  raster_crop <- raster::crop(raster_input, bounding_shape)
  raster_crop <- raster::disaggregate(raster_crop, increase_resolution, method = 'bilinear')
  
  return(raster_crop)
}

library(rayshader)
library(raster)
#> Loading required package: sp

# Tile data taken from: https://land.copernicus.eu/imagery-in-situ/eu-dem/eu-dem-v1.1
# Should also be available at: https://www.dropbox.com/s/bcp4hl9f13walwf/eu_dem_v11_E40N20.TIF?dl=0
tile <- raster("eu_dem_v11_E40N20.TIF")

# this works:
tile_cropped <- crop_raster_square(tile, 42.425738, 8.866535, square_km = 10, 1)
elmat = matrix(extract(tile_cropped, extent(tile_cropped), buffer=1000),
               nrow=ncol(tile_cropped), ncol=nrow(tile_cropped))
elmat %>%
  sphere_shade(texture = "desert", progbar = FALSE) %>%
  plot_map()

ambmat = ambient_shade(elmat, progbar = FALSE)
raymat = ray_shade(elmat, lambert = TRUE, progbar = FALSE)

elmat %>%
  sphere_shade(sunangle = -45, texture = "imhof1", progbar = FALSE) %>%
  add_shadow(raymat, 0.7) %>%
  add_shadow(ambmat, 0.7) %>%
  plot_3d(elmat, zscale=2, fov=10, theta=30, zoom=2, phi=30, solidcolor = "grey30", solidlinecolor = "grey60", linewidth = 0.3, soliddepth = -15)

screen shot 2018-12-19 at 2 09 07 pm

# this doesn't; only difference: square_km argument in crop_raster_square()
tile_cropped <- crop_raster_square(tile, 42.425738, 8.866535, square_km = 15, 1)
elmat = matrix(extract(tile_cropped, extent(tile_cropped), buffer=1000),
               nrow=ncol(tile_cropped), ncol=nrow(tile_cropped))
elmat %>%
  sphere_shade(texture = "desert", progbar = FALSE) %>%
  plot_map()

ambmat = ambient_shade(elmat, progbar = FALSE)
raymat = ray_shade(elmat, lambert = TRUE, progbar = FALSE)

elmat %>%
  sphere_shade(sunangle = -45, texture = "imhof1", progbar = FALSE) %>%
  add_shadow(raymat, 0.7) %>%
  add_shadow(ambmat, 0.7) %>%
  plot_3d(elmat, zscale=2, fov=10, theta=30, zoom=2, phi=30, solidcolor = "grey30", solidlinecolor = "grey60", linewidth = 0.3, soliddepth = -15)
#> Error in if (any(hillshade > 1 || hillshade < 0)) {: missing value where TRUE/FALSE needed

Created on 2018-12-19 by the reprex package (v0.2.1)

Warning message for sphere_shade()

I ran into an issue where when I exported my heightmap for local terrain as an stl file a got a surface instead of a volume. I traced this back to having NA's in my heightmap matrix. Since users will want to treat NA's differently, I figured the best course of action would be just to warn them of the implications. Sorry if this is not what you were thinking to resolve this issue. Just trying to see if I can help.

save_png not write_png

Hi Tyler,
I love your rayshader....
I noticed that updated version should have save_png instead of write_png in Read.me landing page.

write_png save_png Writes the current map to disk with a user-specified filename.

Exporting high resolution images

I think this is an rgl question really, but I'm interested in exporting hi-res images, larger than my screen.

Using rayshader::render_depth I get a screen-sized image and rgl.postscript (suggested here) just hangs because the scene is so large.

Any chance there's a better way to do it?

Feature request: add_water modification

Hey Tyler,

love the work you did here, much appreciated!
I was wondering if it would be possible to have a function to add texture to "air", similarly how add_water adds transparent texture to low areas. So in this way you could have a layer visualizing smog, fog, or clouds. I am working on air pollution data viz, and it would be a great feature to visualize trapped smog in a valley, in addition to "regular" rayshader map.

Thanks

Dataset

Hey Tyler - awesome package :-)

I am trying to figure out how to use it with one of my packages and while playing around with it,
I thought it would probably be nice to have a test dataset for quick exploration of rayshader included in your package? Maybe one of the example datasets you show in the README.

Cheers,
Marco

render_snapshot() not working

Hi, thanks a lot for your work on raycaster, this is an amazing package for R!
I have a small issue with render_snapshopt() - R says there is no such function in the package. I tried both with the CRAN version as well as the github version, and I have the same issue. Is there something that I am missing?

dem_01.tif - Where can we download?

I'm getting this error:

Error in raster::extract(tif_file, raster::extent(tif_file), buffer = 1000) : 
  object 'tif_file' not found

I checked your repo, but couldn't find the file: dem_01.tif

Could you link to this file?

Confusing error message when plot_3d window is already open

Hi Tyler - really enjoying the rayshader package so far! Thanks for putting it together!

If for whatever reason the popup window/render is still open after running plot_3d, when you rerun the pipe (e.g. below), this error message appears:

Error in if (heightmap1[i] < waterheight) { : missing value where TRUE/FALSE needed

Only a very minor issue, but it took some time to realize that a previous code chunk test had successfully rendered and was preventing further testing due to the render being active in another window.

Example code:

bathymetry %>%
sphere_shade(sunangle = 100,  texture = "imhof1") %>%
plot_3d(bathymetry,
            zscale = 10,
            fov = 0,
            theta =- 45,
            phi = 45,
            windowsize = c(1000,800),
            zoom = 0.9,
            water = TRUE,
            waterdepth = 0,
            wateralpha = 0.5,
            watercolor = "lightblue",
            waterlinecolor = "white",
            waterlinealpha = 0.3)

geographic axes with integrated scale

Dug this out of the archive.

Essentially, floating pipes, aligned with grid N,E,S,W that use regular bands of color to communicate equivalent distances. This seems to help with the severe distortion of scale that can happen as the scene is panned / zoomed / tilted. Pipe diameter and distance from the "ground" could be set via argument with default values guessed using grid size and range(z).

perm_detail1
om_detail1

How to make animate the sun angle being rotated?

I see on the front page where the sun rotates around. However do I make the same animation where the sun rotates around the square pole I have set up below??

elmat1 = matrix(0, 500, 500)
elmat1[200:400, 200:400] = 971.0

plotlah <- function(elmat1, sunangle1) {
  elmat1 %>%
    sphere_shade %>%
    add_shadow(ray_shade(elmat1,zscale=3,maxsearch = 300, sunangle = sunangle1),0.5) %>%
    plot_3d(elmat1,zscale=10,fov=0,theta=0,zoom=0.75, phi=25, windowsize = c(1000,800))
  render_snapshot()
}

# I want to animate sunangle = 1:360 each for 0.1s
for(sunangle in 1:360) {
  plotlah(elmat1, 315)
  addplot_to_gif() # how to code this function?
}

In the above I envision a addplot_to_gif() function to build up a gif where each frame is a plot with a different sunangle.

Ideas for extension

First of all, I would like to congratulate you on a great package. I have been watching it since the first version and I also wrote simple wrapper package for determination of shadows with respect to "real" sun position on the sky. It might be worth considering to merge some of this functionality into your package. The enhacements in my package allow: directly use spatial data loaded as raster, estimate sun position based on date and time (possible specified by word - i.e. noon) and specify maximal search distance in real world units (instead of pixels).

The questions are if you would be interested in having this functionality in rayshader and what would be the best way to include them.

How come the second `plot_3d` doesn't update the image?

How do I refresh the plot_3d image?

I have set up this simple plot that should show the shadow at 2 diffferent sunangles.

elmat1 = matrix(0, 500, 500)
elmat1[200:400, 200:400] = 971.0

plotlah <- function(elmat1, sunangle1) {
  elmat1 %>%
    sphere_shade %>%
    add_shadow(ray_shade(elmat1,zscale=3,maxsearch = 300, sunangle = sunangle1),0.5) %>%
    plot_3d(elmat1,zscale=10,fov=0,theta=0,zoom=0.75, phi=25, windowsize = c(1000,800))
  render_snapshot()
}

plotlah(elmat1, 45)
plotlah(elmat1, 315) # doesn't update

However, once the second plotlah doesn't update the image

Setting water level in plot_3d

Here is a simple world with the bottom of a lake at 75m and a small rectangular island topping out at 85m. There is 5 m of water in the lake.

I thought that setting waterdepth = 80 would create the water around the island. However, I end up with underground water. Why is this?

library(magrittr)
library(rayshader)

water <- rep(75, 90)
water_island <- c(rep(75, 30), rep(85, 30), rep(75, 30))

island <- matrix(c(rep(water, 30), rep(water_island, 30), rep(water, 30)),
                 nrow = 90,
                 ncol = 90,
                 byrow = TRUE)

island %>%
  sphere_shade(zscale = 0.1, texture = "imhof1") %>% 
 
  plot_3d(island, zscale = 0.5, fov = 0, theta = -20, phi = 45, windowsize = c(1000, 800), zoom = 0.75,
          water = TRUE, waterdepth = 80, wateralpha = 0.5, watercolor = "lightblue",
          waterlinecolor = "white", waterlinealpha = 0.3)

Screen Shot 2019-04-03 at 10 14 20 PM

plotting_issue

pm.txt

I am trying to plot3d with rayshader function of the attached data, but not able to get the desired output. It should come as an Indian country shape.

pm = read.table(file="pm.txt", sep ="\t", header=T) head(pm) new_filecreate = ggplot(pm, aes(x=lon, y=lat, color=pm)) + geom_hex(bins = 120, size = 0.1) + scale_fill_distiller(palette = "Set1") + #ggtitle("PM2.5 Year 2017") + theme_minimal()+ theme(legend.title=element_blank()) + theme(legend.text=element_text(size=14)) + theme(axis.title = element_text(face="plain",size="14",color="black"),axis.text=element_text(size=14,face="plain", color="black",hjust = 1)) + scale_x_continuous(quote(Longitude)) + scale_y_continuous(quote(Latitude)) + theme(legend.key.height = unit(0.5, "inch"))+ theme(legend.key.width = unit(0.2, "inch")) plot_gg(new_filecreate, width = 4, height = 3, multicore = TRUE,, windowsize=c(1000,1000),fov = 30) render_movie("pm", frames = 350)

please provide some suggestion on this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.