RPlot/01.geom_line.R
生信分析 8289f88ecf 添加 01.geom_line.R
Signed-off-by: 生信分析 <bioinfo@noreply.baihub.cn>
2024-12-13 21:54:36 +08:00

35 lines
915 B
R
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

### 模板说明:
### 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变为长数据形式后再绘制