R : 折线图
# 清空工作环境,删除所有对象
rm(list = ls())
setwd("C:\\Users\\Administrator\\Desktop\\New_microtable\\Co-occurrence Network") #设置工作目录
# 加载必要的包
library(ggplot2)
library(reshape2)
# 创建数据框
data <- data.frame(
Time = c("DAS28", "DAS42", "DAS56", "DAS70"),
B73 = c(0.677, 0.438, 0.412, 0.261),
Mo17 = c(0.956, 1.083, 1.197, 0.485)
)
# 将数据转换为长格式
data_long <- melt(data, id.vars = "Time", variable.name = "Line", value.name = "Value")
# 绘制折线图,并进行个性化设置
plot <- ggplot(data_long, aes(x = Time, y = Value, color = Line, group = Line)) +
geom_line(size = 1.5) + # 线条的粗细
geom_point(size = 4) + # 点的大小
labs(y = "Modularity",x = NULL) +
theme_minimal() +
theme(
panel.grid.major = element_blank(), # 去除主网格线
panel.grid.minor = element_blank(), # 去除次网格线
panel.background = element_rect(fill = "white", colour = "white"), # 设置背景颜色为白色
plot.background = element_rect(fill = "white", colour = "white"), # 设置绘图区域的背景颜色为白色
axis.title = element_text(size = 14, face = "plain"), # 坐标轴标题的字体大小和加粗
axis.text = element_text(size = 12, colour = "black"), # 坐标轴刻度的字体大小和颜色
axis.line = element_line(size = 1, colour = "black"), # 坐标轴线的宽度和颜色
axis.ticks = element_line(size = 1), # 坐标轴刻度线的宽度
axis.ticks.length = unit(0.25, "cm"),# 坐标轴刻度线的长度
legend.position = "none" # 去掉图例
) +
scale_color_manual(values = c("B73" = "#8FC9E2", "Mo17" = "#ECC97F")) # 自定义线条颜色
# 保存为PNG格式,设置长宽和分辨率
ggsave("Modularity.png", plot = plot, width = 4, height = 3, units = "in", dpi = 1200)