Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3D Rendering offset - Heights vs Poligons and Colors [¿BUG?] #284

Open
ssilveram opened this issue Jun 27, 2023 · 5 comments
Open

3D Rendering offset - Heights vs Poligons and Colors [¿BUG?] #284

ssilveram opened this issue Jun 27, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@ssilveram
Copy link

Describe the bug
Hi!

I'm trying to make a 3D render of a population map. When I plot using ggplot, I obtain the map on the right side of the following image, but when I try to create a 3D render of it, the results are as you can see on the left side of the image.

image

As you can see, in the 3D render, the heights are dissaligned with the colors. Really I don't know why it's happening, but I think maybe is a bug or incompatibility with my machine. Anyone can help me?

Thanks a lot!

You can find the code below

Session Info
Information of sessionInfo():

R version 4.2.3 (2023-03-15 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=Spanish_Spain.utf8  LC_CTYPE=Spanish_Spain.utf8    LC_MONETARY=Spanish_Spain.utf8 LC_NUMERIC=C                  
[5] LC_TIME=Spanish_Spain.utf8    

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

other attached packages:
 [1] rayrender_0.29.4  rayshader_0.24.10 viridis_0.6.3     viridisLite_0.4.1 patchwork_1.1.2   lubridate_1.9.2   forcats_1.0.0    
 [8] stringr_1.5.0     dplyr_1.1.1       purrr_1.0.1       readr_2.1.4       tidyr_1.3.0       tibble_3.2.1      ggplot2_3.4.2    
[15] tidyverse_2.0.0   sf_1.0-12        

loaded via a namespace (and not attached):
 [1] rgl_1.1.3          Rcpp_1.0.10        prettyunits_1.1.1  png_0.1-8          class_7.3-21       digest_0.6.31     
 [7] foreach_1.5.2      utf8_1.2.3         R6_2.5.1           e1071_1.7-13       pillar_1.9.0       rlang_1.1.0       
[13] progress_1.2.2     rstudioapi_0.14    extrafontdb_1.0    textshaping_0.3.6  extrafont_0.19     htmlwidgets_1.6.2 
[19] munsell_0.5.0      proxy_0.4-27       compiler_4.2.3     xfun_0.38          systemfonts_1.0.4  pkgconfig_2.0.3   
[25] base64enc_0.1-3    htmltools_0.5.5    tidyselect_1.2.0   gridExtra_2.3      codetools_0.2-19   fansi_1.0.4       
[31] crayon_1.5.2       tzdb_0.3.0         withr_2.5.0        grid_4.2.3         jsonlite_1.8.4     Rttf2pt1_1.3.12   
[37] gtable_0.3.3       lifecycle_1.0.3    DBI_1.1.3          magrittr_2.0.3     units_0.8-1        scales_1.2.1      
[43] KernSmooth_2.23-20 cli_3.6.1          stringi_1.7.12     farver_2.1.1       doParallel_1.0.17  terrainmeshr_0.1.0
[49] ragg_1.2.5         generics_0.1.3     vctrs_0.6.1        iterators_1.0.14   tools_4.2.3        glue_1.6.2        
[55] hms_1.1.3          parallel_4.2.3     fastmap_1.1.1      timechange_0.2.0   colorspace_2.1-1   classInt_0.4-9    
[61] knitr_1.42  

Reproducible Example
The code to load data, plot and the 3D render:

#My code:

library(sf)
library(tidyverse)
library(patchwork)
library(viridisLite)
library(viridis)
library(rayshader)
library(rayrender)

Shape_Manzanas <- st_read("https://www.silvera.com.co/portal/santiago/other_files/Shape_BOG_Manzanas_v1.gpkg")

Ploteo <- Shape_Manzanas %>%
  ggplot(
  ) +
  geom_sf(
    aes(
      fill = PERSONAS_MNZ,
    ),
    color = NA,
  ) +
  scale_fill_viridis() +
  theme(
    line = element_blank(),
    legend.position = "none",
    axis.text = element_blank(),
    axis.line = element_blank(),
    axis.ticks = element_blank(),
    panel.background = element_blank(),
    panel.grid = element_blank(),
  ) +
  labs(x = NULL,
       y = NULL,
       borders = NULL,)
Ploteo

rgl::close3d()
plot_gg(
  ggobj = Ploteo,
  multicore = TRUE,
  windowsize = c(1366,768),
  offset_edges = FALSE,
)

Thanks for your help.

@ssilveram ssilveram added the bug Something isn't working label Jun 27, 2023
@ssilveram ssilveram changed the title Concise description of the bug [BUG] 3D Rendering offset - Heights vs Poligons and Colors [¿BUG?] Jun 28, 2023
@Tanggong
Copy link

I am expericing the same issue, also while tryting to plot 3D from 2D ggplot
grafik

@ssilveram
Copy link
Author

I am expericing the same issue, also while tryting to plot 3D from 2D ggplot grafik

Finally, it was solved with the last update of the library. Now, I don't have this issue and the 3D Plot looks pretty nice. =)

@Tanggong
Copy link

Tanggong commented Aug 21, 2023

I am expericing the same issue, also while tryting to plot 3D from 2D ggplot grafik

Finally, it was solved with the last update of the library. Now, I don't have this issue and the 3D Plot looks pretty nice. =)

I installed the packages from github repo, but still got this problem... Hier is my code:

library(sf)             # Load the sf package, simple feature,to load geometries
library(ggplot2)       # Load ggplot2 render the graphic
library(rayshader)


# Load data
cities_gjson <- st_read("dichte_2021_poly_g50.geojson")  #data for all cities larger than 50000 EW

# Preprocessing, covert value to numeric
cities_gjson$value<-as.numeric(cities_gjson$value)

# reproject to WGS84
cities_gjson <- st_transform(cities_gjson, crs = 4326)

# customerize map color
gradianColor <- grDevices::colorRampPalette(c("#fef0d9","#fdcc8a", "#fc8d59", "#d7301f"), bias=2)(256)

# Draw the plot
cities = ggplot() +
  geom_sf(data = cities_gjson, aes(fill = value), color = NA)+
  scale_fill_gradientn(limits=range(cities_gjson$value), colours = gradianColor, name = "Siedlungsdichte (%)")

# 3D Plot
plot_gg(ggobj = cities,        
        multicore = TRUE,
        scale = 150,
        sunangle = 135,
        width = 5)

@Tanggong
Copy link

I am expericing the same issue, also while tryting to plot 3D from 2D ggplot grafik

Finally, it was solved with the last update of the library. Now, I don't have this issue and the 3D Plot looks pretty nice. =)

I installed the packages from github repo, but still got this problem... Hier is my code:

library(sf)             # Load the sf package, simple feature,to load geometries
library(ggplot2)       # Load ggplot2 render the graphic
library(rayshader)


# Load data
cities_gjson <- st_read("dichte_2021_poly_g50.geojson")  #data for all cities larger than 50000 EW

# Preprocessing, covert value to numeric
cities_gjson$value<-as.numeric(cities_gjson$value)

# reproject to WGS84
cities_gjson <- st_transform(cities_gjson, crs = 4326)

# customerize map color
gradianColor <- grDevices::colorRampPalette(c("#fef0d9","#fdcc8a", "#fc8d59", "#d7301f"), bias=2)(256)

# Draw the plot
cities = ggplot() +
  geom_sf(data = cities_gjson, aes(fill = value), color = NA)+
  scale_fill_gradientn(limits=range(cities_gjson$value), colours = gradianColor, name = "Siedlungsdichte (%)")

# 3D Plot
plot_gg(ggobj = cities,        
        multicore = TRUE,
        scale = 150,
        sunangle = 135,
        width = 5)

ok, it works well without the colorbar legend

@matteodefelice
Copy link

same problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants