❝
本節來介紹如何使用「ggplot2繪制3D熱圖」,很簡單的一個小案例
❞
加載R包
library(rayshader)
library(tidyverse)
library(scales)
sets <- readr::read_csv('sets.csv') %>% dplyr::filter(num_parts >1)
gg <- ggplot(sets,aes(x = num_parts, y = year))
geom_bin2d(bins = 30, color = NA)
labs(x =NULL, y=NULL)
scale_x_log10(expand=c(0,0))
scale_y_continuous(expand=c(0,0))
scale_fill_gradientn(
colours = c("#6c98c9","#0A69AE","#328349","#A5BC45","#E4CD9E","#F2CD37","#C91A09"),
values = scales::rescale(c(0,0.05,0.1, 0.2, 0.35, 0.5, 1)))
theme_test()
theme(
axis.text=element_text(color="black"),
plot.background = element_rect(color = NA, fill = "#ffffff"),
panel.background = element_rect(color = NA, fill = "#ffffff"),
plot.margin = margin(t=0.2,r=0.2,l=0.2,b=0.2,unit = "cm"),
panel.grid.major =element_blank(),
panel.grid.minor = element_blank(),
legend.title =element_blank(),
legend.text = element_text(size =8,color="black"))
guides(fill=guide_colorbar(direction="vertical",reverse=F,barwidth=unit(.5,"cm"),
barheight=unit(10,"cm")))
rayshader::plot_gg(
gg,
multicore = TRUE,
shadow_intensity = 0.5,
width=5,
height=5,
scale = 60,
preview = TRUE,
raytrace = TRUE,
triangulate = FALSE,
offset_edges = TRUE)
本文首發于微信公衆号R語言數據分析指南,更多精彩内容請關注公衆号,下回更新不迷路
,更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!