-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpop_3d_plot.R
41 lines (36 loc) · 1.15 KB
/
pop_3d_plot.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
library(sf)
library(maps)
library(rayshader)
library(ggplot2)
library(tidyverse)
library(viridis)
library(viridisLite)
library(reshape2)
library(rayrender)
library(av)
library(ggdark)
#Data Import
ind <- read_excel("C:/Users/Anup Kumar/Downloads/ind.xlsx")
# Convert data to long format
pop_ind <- pivot_longer(ind,
cols = -Year,
names_to = "Age_Category",
values_to = "Population")
#Plot Graph
pop_gg = ggplot(pop_ind) +
geom_raster(aes(x = Year, y = Age_Category, fill = Population)) +
scale_x_continuous("Year", breaks = seq(1950, 2021, 10)) +
scale_fill_viridis(
"Population (in million)",
breaks = c(1000000, 234000000, 467000000, 700000000),
labels = c("1", "234", "467", "700")
) +
ylab("Age Category")+
dark_theme_classic()+
theme(panel.grid = element_blank())+
labs(title = "Population by Age Group,India 1950-2021 ",
caption = "Source: United Nations, World Population Prospects (2022)")
#Make 3D Plot
plot_gg(pop_gg,height = 5, width = 6 )
#Make Movie
render_movie(filename = "pop.mp4",type = "orbit",frames = 360)