其他
rayshader三维可视化ggplots图表
rayshader三维可视化ggplots图表
R语言rayshader
包已经发布2年了,作者Tyler大神又搞出了新花样,能够用颜色或数值3D可视化ggplot图表,快来看看吧。
rayshader
包已经在CRAN发布,可以直接安装经过测试的代码:
library(tidyverse)
library(rayshader)
library(viridis)
measles = read_csv("https://tylermw.com/data/measles_country_2011_2019.csv")
melt_measles = reshape2::melt(measles, id.vars = c("Year", "Country", "Region", "ISO3"))
melt_measles$Month = melt_measles$variable
melt_measles$cases = melt_measles$value
melt_measles %>%
group_by(Year, Month) %>%
summarize(totalcases = sum(cases,na.rm = TRUE)) %>%
mutate(totalcases = ifelse(Year == 2019 & !(Month %in% c("January","February","March")), NA, totalcases)) %>%
ggplot() +
geom_tile(aes(x=Year, y=Month, fill=totalcases,color=totalcases),size=1,color="black") +
scale_x_continuous("Year", expand=c(0,0), breaks = seq(2011,2019,1)) +
scale_y_discrete("Month", expand=c(0,0)) +
scale_fill_viridis("Total\nCases") +
ggtitle("Reported Worldwide Measles Cases") +
labs(caption = "Data Source: WHO") +
theme(axis.text = element_text(size = 12),
title = element_text(size = 12,face="bold"),
panel.border= element_rect(size=2,color="black",fill=NA)) ->
measles_gg
plot_gg(measles_gg, multicore = TRUE, width = 6, height = 5.5, scale = 300,
background = "#afceff",shadowcolor = "#3a4f70")
测试发现,代码执行完成后会弹出一个RGL device窗口,用鼠标左键可以旋转。
还可以使用plot_3d
和render_snapshot
制作3D渲染图
人家的渲染图
参考文献
https://www.tylermw.com/3d-ggplots-with-rayshader/ https://wcmbishop.github.io/rayshader-demo/
点击阅读原文,查看Tyler大神作品