唯有敬意,祝祖国母亲生日快乐
❝
1949.10.1 - 2024.10.1
庆祝我的祖国75周年华诞!此时此刻,唯有敬意~祝愿我的祖国繁荣富强!
❝作为一名共和国的码农&数据分析师,那么今天的推文:使用
R
语言绘制一张中国国旗!效果如下:
直接上代码:
加载R
包
rm(list = ls())
####----laod R Package----####
library(ggplot2)
library(dplyr)
library(showtext)
font_families()
showtext_auto()
加载数据
####----load Data----####
data <- data.frame(x = numeric(), y = numeric(), ID = integer())
# 红色背景 (矩形区域)
background <- data.frame(
x = c(-15, 15, 15, -15, -15),
y = c(10, 10, -10, -10, 10),
ID = 1
)
# 大五角星 (中心点(-10, 5), 半径为3)
main_star <- data.frame(
x = sapply(1:6, function(i) 3 * sin((i - 1) * 4 * pi / 5) - 10),
y = sapply(1:6, function(i) 3 * cos((i - 1) * 4 * pi / 5) + 5),
ID = 2
)
# 第一颗小五角星 (中心点(-5, 8), 半径为1)
small_star_1 <- data.frame(
x = sapply(1:6, function(i) sin((i - 1) * 4 * pi / 5 - (pi - atan(5 / 3))) - 5),
y = sapply(1:6, function(i) cos((i - 1) * 4 * pi / 5 - (pi - atan(5 / 3))) + 8),
ID = 3
)
# 第二颗小五角星 (中心点(-3, 6), 半径为1)
small_star_2 <- data.frame(
x = sapply(1:6, function(i) sin((i - 1) * 4 * pi / 5 - (pi - atan(7))) - 3),
y = sapply(1:6, function(i) cos((i - 1) * 4 * pi / 5 - (pi - atan(7))) + 6),
ID = 4
)
# 第三颗小五角星 (中心点(-3, 3), 半径为1)
small_star_3 <- data.frame(
x = sapply(1:6, function(i) sin((i - 1) * 4 * pi / 5 - atan(7 / 2)) - 3),
y = sapply(1:6, function(i) cos((i - 1) * 4 * pi / 5 - atan(7 / 2)) + 3),
ID = 5
)
# 第四颗小五角星 (中心点(-5, 1), 半径为1)
small_star_4 <- data.frame(
x = sapply(1:6, function(i) sin((i - 1) * 4 * pi / 5 - atan(5 / 4)) - 5),
y = sapply(1:6, function(i) cos((i - 1) * 4 * pi / 5 - atan(5 / 4)) + 1),
ID = 6
)
# 合并所有数据
all_data <- bind_rows(background, main_star, small_star_1, small_star_2, small_star_3, small_star_4)
可视化
####----Plot----####
p <- ggplot(all_data, aes(x = x, y = y, group = ID)) +
geom_polygon(aes(fill = factor(ID)), color = NA) +
scale_fill_manual(values = c("red", rep("yellow", 5))) +
coord_fixed() +
theme_void() +
theme(legend.position = "none")
ggsave(filename = "p.pdf",
height = 6.67,
width = 10)
版本信息
####----sessionInfo----####
sessionInfo()
R version 4.3.0 (2023-04-21)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS 14.6.1
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: Asia/Shanghai
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] showtext_0.9-6 showtextdb_3.0 sysfonts_0.8.8 lubridate_1.9.3 forcats_1.0.0 stringr_1.5.1 dplyr_1.1.4
[8] purrr_1.0.2 readr_2.1.5 tidyr_1.3.1 tibble_3.2.1 tidyverse_2.0.0 ggstar_1.0.4 ggplot2_3.5.1
loaded via a namespace (and not attached):
[1] gtable_0.3.5 compiler_4.3.0 tidyselect_1.2.1 gridExtra_2.3 textshaping_0.3.7 systemfonts_1.1.0
[7] scales_1.3.0 R6_2.5.1 labeling_0.4.3 generics_0.1.3 munsell_0.5.1 pillar_1.9.0
[13] tzdb_0.4.0 rlang_1.1.4 utf8_1.2.4 stringi_1.8.3 timechange_0.2.0 cli_3.6.3
[19] withr_3.0.1 magrittr_2.0.3 grid_4.3.0 rstudioapi_0.15.0 hms_1.1.3 lifecycle_1.0.4
[25] vctrs_0.6.5 glue_1.7.0 farver_2.1.2 ragg_1.2.6 fansi_1.0.6 colorspace_2.1-1
[31] tools_4.3.0 pkgconfig_2.0.3
历史绘图合集
进化树合集
环状图
散点图
基因家族合集
换一个排布方式:
首先查看基础版热图:
然后再看进阶版热图:
基因组共线性
WGCNA ggplot2版本
其他科研绘图
合作、联系和交流
有很多小伙伴在后台私信作者,非常抱歉,我经常看不到导致错过,请添加下面的微信联系作者,一起交流数据分析和可视化。