From 8289f88ecf4d1f54ac884e20e21d104a1e889d6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=9F=E4=BF=A1=E5=88=86=E6=9E=90?= Date: Fri, 13 Dec 2024 21:54:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=2001.geom=5Fline.R?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 生信分析 --- 01.geom_line.R | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 01.geom_line.R diff --git a/01.geom_line.R b/01.geom_line.R new file mode 100644 index 0000000..b9962f2 --- /dev/null +++ b/01.geom_line.R @@ -0,0 +1,34 @@ +### 模板说明: +### ggplot2画多变量折线图,共用x轴 + + +# 一、最原始办法——手动画每条变量折线 +library(ggplot2) + +dat <- data.frame( + water_press = c(2, 4, 6), + out_volumn = c(1.5, 4, 6), + in_volumn = c(1, 3, 5) +) + +pdf("Dr.Liang.pdf", width = 7, height = 5, family = "GB1") +ggplot(dat) + + theme_classic() + + geom_point(aes(x = water_press, y = out_volumn, col = "c")) + + geom_line(aes(x = water_press, y = out_volumn, col = "c")) + + geom_point(aes(x = water_press, y = in_volumn, col = "d")) + + geom_line(aes(x = water_press, y = in_volumn, col = "d")) + + ggtitle("Dr.Liang 的病生实验") + + xlab("水检压计") + + ylab("容积变化") + + #手动设置图例 + scale_color_manual( + values = c("c" = "#000080", "d" = "#df6100"), + name = "变量", + labels = c("充气容积", "抽气容积") + ) +dev.off() + + +# 二、将dataFrame变为长数据形式后再绘制 +