R语言绘图

ops/2025/1/19 20:57:40/

多组火山图

数据准备:

将CSV文件同一在一个路径下,用代码合并

确保文件列名正确

library(fs)
library(dplyr)
library(tidyr)
library(stringr)
library(ggplot2)
library(ggfun)
library(ggrepel)# 获取文件列表
file_paths <- dir_ls(path = "E:\\proteomic\\fuxian_bacteria\\multivolcano", pattern = "_DEG\\.csv$", full.names = T)
# 检查文件列表
print(file_paths)# 读取和处理数据
all_deg <- map(file_paths, function(x){# 检查文件扩展名,忽略大小写if (str_ends(str_to_lower(x), ".csv")) {cat("Processing file:", x, "\n") # 打印正在处理的文件名data <- read_delim(file = x, col_names = T, delim = ",")if (is.data.frame(data)) {group <- str_remove(basename(x), pattern = "_DEG.*")return(dplyr::mutate(data, group = group))} else {cat("Failed to read file:", x, "\n")return(NULL)}} else {cat("Skipping non-CSV file:", x, "\n")return(NULL)}
}) %>%compact() %>% # 移除列表中的 NULL 元素do.call(rbind, .)ggplot(data = all_deg) +geom_jitter(data = all_deg %>% dplyr::filter(change == "Normal"),aes(x = group, y = logFC, color = change, size = abs(logFC), alpha = abs(logFC)),width = 0.4) +geom_jitter(data = all_deg %>% dplyr::filter(change != "Normal"),aes(x = group, y = logFC, color = change, size = abs(logFC), alpha = abs(logFC)),width = 0.4) +geom_jitter(data = all_deg %>% dplyr::group_by(group) %>%dplyr::arrange(desc(abs(logFC))) %>%dplyr::slice_head(n = 15) %>%dplyr::ungroup() %>%na.omit(),aes(x = group, y = logFC, size = abs(logFC)),width = 0.4, shape = 21, fill = "#e77381") +geom_text_repel(data = all_deg %>% dplyr::group_by(group) %>%dplyr::arrange(desc(abs(logFC))) %>%dplyr::slice_head(n = 15) %>%dplyr::ungroup() %>%na.omit(),aes(x = group, y = logFC, label = SYMBOL)) +geom_tile(aes(x = group, y = 0, fill = group), height = 0.4) +geom_text(data = all_deg %>% dplyr::select(group) %>% dplyr::distinct(group, .keep_all = T),aes(x = group, y = 0, label = group), size = 6) +geom_hline(yintercept = c(-log2(1.5), log2(1.5))) +scale_y_continuous(limits = c(-5, 5)) +scale_size(range = c(1, 10)) +scale_alpha(range = c(0.1, 1)) +scale_color_manual(values = c("Up" = "#f46d43", "Normal" = "#bdbdbd", "Down" = "#3288bd")) +scale_fill_manual(values = c('#8dd3c7','#ffffb3','#bebada','#fb8072','#80b1d3')) +theme_bw() +theme(axis.text = element_text(color = "#000000", size = 12),axis.title = element_text(color = "#000000", size = 15),panel.grid = element_blank(),legend.background = element_roundrect(color = "#969696")) +labs(y = "log2(Fold Change)")

中国地图

不分类地形图

自然地球 » 1:50m 自然地球 I - 1:10m、1:50m 和 1:110m 比例的自由矢量和栅格地图数据该地址下载水纹地图,获得.tif文件

install.packages("geodata")
install.packages("terra")
install.packages("tidyterra")
install.packages("ggspatial")
install.packages("mapchina")
install.packages("ggmapcn")
install.packages("raster")
library(tidyverse)
library(geodata)
library(terra)
library(mapchina)
library(ggmapcn)
library(sf)
library(raster)
library(ggplot2)
library(tidyterra)
library(ggspatial)
library(tibble)
library(ggsci)
library(dplyr)# 创建包含城市名称、纬度和经度的数据框
hospital_locations <- tibble(city = c("南京", "北京", "昆明", "郑州", "上海", "南昌", "乌鲁木齐", "杭州","海口", "成都", "南宁", "重庆", "哈尔滨", "济南", "广州", "武汉"),latitude = c(32.0583, 39.9042, 25.0459, 34.7565, 31.2304, 28.6824, 43.8257, 30.2728,20.0171, 30.5728, 22.8155, 29.5331, 45.7566, 36.6539, 23.1291, 30.5828),longitude = c(118.7978, 116.4074, 102.7282, 113.6294, 121.4737, 115.8547, 87.5842, 120.1544,110.3385, 104.0668, 108.3211, 106.5515, 126.6632, 117.0009, 113.2644, 114.3055)
)# 将数据框转换为简单特征(Simple Features)对象
travel_st_as_sf <- st_as_sf(hospital_locations, coords = c("longitude", "latitude"), crs = 4326)
# China Map with Shaded Relief and Water----------------------------------------------------------------
china_map <- sf::st_read("https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json")[c("adcode", "name", "geometry")]
nat.earth <- raster::brick("E:\\proteomic\\fuxian_bacteria\\NE1_50M_SR_W\\NE1_50M_SR_W.tif")
ggplot(china_map) +
theme_bw() +
layer_spatial(nat.earth)+
geom_sf(fill = "white", color = 'black', size = 1.2) +
geom_sf(data = travel_st_as_sf, shape = 21, fill = "#07519c", size = 2) +
annotation_north_arrow(location = "tl", which_north = F,
pad_x = unit(0.05, "in"),
pad_y = unit(0.05, "in"),
style = north_arrow_fancy_orienteering) +
theme(axis.text = element_text(size = 12, color = "black"),axis.line = element_blank(),panel.background = element_rect("white")) +# 地图底层颜色设置coord_sf(ylim = c(-3687082, 1654989),xlim = c(-3000000, 2700000),crs = "+proj=laea +lat_0=40 +lon_0=104") +annotation_scale(location = "bl", width_hint = 0.3) +labs(x = '', y = '', color = NULL)

分类地形图

cr_hvkp <- tibble(city = c("南京", "北京", "昆明", "郑州", "上海","上海", "南昌", "乌鲁木齐", "杭州", "杭州"),Latitude = c(32.0583, 39.9042, 25.0459, 34.7565, 31.2304,31.2304, 28.6824, 43.8257, 30.2728, 30.2728),Longitude = c(118.7978, 116.4074, 102.7282, 113.6294, 121.4737,  121.4737, 115.8547, 87.5842, 120.1544, 120.1544),Category = "CR-hvKP"
)cs_hvkp <- tibble(city = c("南昌","昆明", "北京", "北京","海口", "成都", "南宁","重庆","哈尔滨","济南"),Latitude = c(28.6824,25.0459, 39.9042,39.9042, 20.0171, 30.5728, 22.8155, 29.5331, 45.7566, 36.6539),Longitude = c(115.8547,102.7282, 116.4074,116.4074, 110.3385, 104.0668, 108.3211, 106.5515, 126.6632, 117.0009),Category = "CS-hvKP"
)cr_ckp <- tibble(city = c("重庆", "广州", "武汉", "上海", "昆明"),Latitude = c(29.5331, 23.1291, 30.5828, 31.2304, 25.0459),Longitude = c(106.5515, 113.2644, 114.3055, 121.4737, 102.7282),Category= "CR-cKP"
)cs_ckp <- tibble(city = c("昆明", "武汉", "杭州", "哈尔滨", "成都"),Latitude = c(25.0459, 30.5828, 30.2728, 45.7566, 30.5728),Longitude = c(102.7282, 114.3055, 120.1544, 126.6632, 104.0668),Category = "CS-cKP"
)# 合并所有数据
all_data <- bind_rows(cr_ckp, cs_ckp,cr_hvkp, cs_hvkp)
all_data <- all_data[,-1]ggplot() +geom_mapcn() +  theme_minimal()+geom_loc(data = all_data, lon = "Longitude", lat = "Latitude",mapping = aes(color = Category), size = 3, alpha = 0.7) +scale_color_manual(values = c("CR-hvKP" = "red", "CS-hvKP" = "blue", "CR-cKP" = "green", "CS-cKP" = "yellow")) +
theme_bw()


http://www.ppmy.cn/ops/151474.html

相关文章

SpringMVC 实战指南:文件上传

第一章&#xff1a;常用的注解&#xff1a; RequestParam 注解&#xff1a; 作用&#xff1a;把请求中的指定名称的参数传递给控制器中的形参赋值属性&#xff1a; value&#xff1a;请求参数中的名称required&#xff1a;请求参数中是否必须提供此参数&#xff0c;默认值是 tr…

智能家居企业如何通过设计师渠道打造第二曲线?

随着智能家居行业的迅速发展和消费者需求的不断升级&#xff0c;企业的营销策略也在不断变化。传统的B2C营销模式逐渐让位于更加精细化、定制化的B2B2C模式&#xff0c;其中设计师渠道的开发与合作&#xff0c;成为智能家居企业布局市场、提升品牌影响力的关键。 智能家居推广的…

Redis的安装和配置、基本命令

一、实验目的 本实验旨在帮助学生熟悉Redis的安装、配置和基本使用&#xff0c;包括启动Redis服务、使用命令行客户端进行操作、配置Redis、进行多数据库操作以及掌握键值相关和服务器相关的命令。 二、实验环境准备 1. JAVA环境准备&#xff1a;确保Java Development Kit …

Python爬虫学习前传 —— Python从安装到学会一站式服务

早上好啊&#xff0c;大佬们。我们的python基础内容的这一篇终于写好了&#xff0c;啪唧啪唧啪唧…… 说实话&#xff0c;这一篇确实写了很久&#xff0c;一方面是在忙其他几个专栏的内容&#xff0c;再加上生活学业上的事儿&#xff0c;确实精力有限&#xff0c;另一方面&…

家政服务小程序,打造智慧家政新体验

春节即将来临&#xff0c;家政市场呈现出了火热的场景&#xff0c;大众对家政服务的需求持续增加。 近年来&#xff0c;家政市场开始倾向数字化、智能化&#xff0c;借助科学技术打造家政数字化平台&#xff0c;让大众在手机上就可以预约家政服务&#xff0c;减少传统家政市场…

WPS数据分析000004

目录 一、表格阅读技巧 冻结窗格 拆分窗口 新建窗口 阅读模式 护眼模式 二、表格打印技巧 打印预览 打印缩放 打印区域 打印标题 分页打印 打印位置 页眉页脚 逐份打印 三、表格保护技巧 锁定单元格 隐藏公式 文档权限 文件加密 一、表格阅读技巧 冻结窗…

K8S中的Pod生命周期之重启策略

三种策略 Kubernetes 中的 Pod 支持以下三种重启策略&#xff1a; Always&#xff1a; 描述&#xff1a;无论容器退出的原因是什么&#xff0c;都会自动重启容器。 默认值&#xff1a;如果未指定重启策略&#xff0c;Kubernetes 默认使用 Always。 OnFailure&#xff1a; 描…

C 语言的void*到底是什么?

一、void* 的类型任意性 void* 是一种通用指针类型。它可以指向任意类型的数据。例如&#xff0c;它可以指向一个整数&#xff08;int&#xff09;、一个浮点数&#xff08;float&#xff09;、一个字符&#xff08;char&#xff09;或者一个结构体等。在C语言中&#xff0c;当…