多组火山图
数据准备:
将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()