0

Based on the code and data below how can I get an output similar to the desired output?

Current output:

enter image description here

2D output:

enter image description here

Desired 3D output (obtained from here):

enter image description here

Code + data:

library(tidyverse)
library(maps)
library(rayshader)

# Read the state population data
StatePopulation = read.csv("https://raw.githubusercontent.com/ds4stats/r-tutorials/master/intro-maps/data/StatePopulation.csv", as.is = TRUE)


# Plot all states with ggplot2, using black borders and light blue fill
# Load United States state map data
MainStates = map_data("state")

# Use the dplyr package to merge the MainStates and StatePopulation files
MergedStates = inner_join(MainStates, StatePopulation, by = "region")

MainCities = filter(us.cities, long >= -130)

# 2D
g = ggplot()
g = g + geom_polygon(data = MergedStates, 
            aes(x = long, 
                y = lat, 
                group = group, 
                fill = population/1000000), 
                color = "black", 
                size = 0.2) + 
  
      scale_fill_continuous(name = "State Population",
                            low = "lightblue", 
                            high = "darkblue",
                            limits = c(0,40), 
                            breaks = c(5,10,15,20,25,30,35), 
                            na.value = "grey50") +
  
      labs(title="Population (in millions) in the Mainland United States")

g_pt = g + geom_point(data = MainCities, 
                      aes(x = long, 
                          y = lat, 
                          size = pop/1000000), 
                          color = "gold", 
                          alpha = .5) + scale_size(name = "City Population")
# 3D
plot_gg(g_pt,
        raytrace = TRUE,
        multicore = TRUE,
        width = 5,
        height = 3,
        scale = 310)
Ed_Gravy
  • 1,841
  • 2
  • 11
  • 34
  • 2
    Could you please clarify what exactly should be different?! – TarJae Nov 22 '22 at 17:26
  • You know like in my output the points are not showing as 3D bars similar to the ones seen in the desired output. – Ed_Gravy Nov 22 '22 at 18:11
  • I am also open to other ways of showing the 2D map in 3D which may make more sense than the desired output using `rayshader`. – Ed_Gravy Nov 22 '22 at 18:18
  • Plus the legend in my 3D output is also messed up, so I guess this needs to be fixed too. – Ed_Gravy Nov 22 '22 at 19:18
  • 1
    I am sorry, I tried a little but had no success. Good luck! – TarJae Nov 22 '22 at 19:34
  • If you edit the question, would it help attracting more attention to the question? – Ed_Gravy Nov 22 '22 at 19:39
  • 1
    One issue is that handling with rayshader procedures is really heavy lifting for the machine. So I would make a minimal reproducible example with one City, I would also go through step by step the linked tutorial.... – TarJae Nov 22 '22 at 19:41

0 Answers0