# 清空工作環境,刪除所有物件
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)