tft每日頭條

 > 生活

 > ggplot2繪圖如何将底色改為白色

ggplot2繪圖如何将底色改為白色

生活 更新时间:2024-07-22 09:14:09
歡迎關注R語言數據分析指南

本節來介紹如何使用「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")))

轉換為3D圖形

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)

ggplot2繪圖如何将底色改為白色(ggplot2優雅的繪制3D熱圖)1

本文首發于微信公衆号R語言數據分析指南,更多精彩内容請關注公衆号,下回更新不迷路

,

更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!

查看全部

相关生活资讯推荐

热门生活资讯推荐

网友关注

Copyright 2023-2024 - www.tftnews.com All Rights Reserved