更新 01.geom_line.R
Signed-off-by: 生信分析 <bioinfo@noreply.baihub.cn>
This commit is contained in:
parent
8289f88ecf
commit
70e1577b61
@ -1,6 +1,33 @@
|
|||||||
### 模板说明:
|
### 模板说明:
|
||||||
### ggplot2画多变量折线图,共用x轴
|
### ggplot2画多变量折线图,共用x轴
|
||||||
|
|
||||||
|
###快速使用(最终推荐)
|
||||||
|
library(ggplot2)
|
||||||
|
|
||||||
|
dat <- reshape::melt(data.frame(
|
||||||
|
water_press = c(2, 4, 6),
|
||||||
|
抽气容积 = c(1.5, 4, 6),
|
||||||
|
充气容积 = c(1, 3, 5)
|
||||||
|
), "water_press")
|
||||||
|
|
||||||
|
pdf("Dr.Liang.pdf", width = 7, height = 5, family = "GB1")
|
||||||
|
ggplot(dat, aes(x = water_press, y = value, col = variable)) +
|
||||||
|
theme_classic() +
|
||||||
|
geom_point() +
|
||||||
|
geom_line() +
|
||||||
|
labs(
|
||||||
|
x = "水检压计",
|
||||||
|
y = "容积变化",
|
||||||
|
title = "Dr.Liang 的病生实验",
|
||||||
|
color = "变量"
|
||||||
|
) +
|
||||||
|
scale_color_manual(
|
||||||
|
#自定义每个变量的颜色
|
||||||
|
values = c("#000080", "#df6100")
|
||||||
|
)
|
||||||
|
dev.off()
|
||||||
|
###快速使用
|
||||||
|
|
||||||
|
|
||||||
# 一、最原始办法——手动画每条变量折线
|
# 一、最原始办法——手动画每条变量折线
|
||||||
library(ggplot2)
|
library(ggplot2)
|
||||||
@ -31,4 +58,29 @@ dev.off()
|
|||||||
|
|
||||||
|
|
||||||
# 二、将dataFrame变为长数据形式后再绘制
|
# 二、将dataFrame变为长数据形式后再绘制
|
||||||
|
library(ggplot2)
|
||||||
|
|
||||||
|
dat <- reshape::melt(data.frame(
|
||||||
|
water_press = c(2, 4, 6),
|
||||||
|
out_volumn = c(1.5, 4, 6),
|
||||||
|
in_volumn = c(1, 3, 5)
|
||||||
|
), "water_press")
|
||||||
|
|
||||||
|
pdf("Dr.Liang.pdf", width = 7, height = 5, family = "GB1")
|
||||||
|
ggplot(dat, aes(x = water_press, y = value, col = variable)) +
|
||||||
|
theme_classic() +
|
||||||
|
geom_point() +
|
||||||
|
geom_line() +
|
||||||
|
labs(
|
||||||
|
x = "水检压计",
|
||||||
|
y = "容积变化",
|
||||||
|
title = "Dr.Liang 的病生实验",
|
||||||
|
color = "变量"
|
||||||
|
) +
|
||||||
|
scale_color_manual(
|
||||||
|
#自定义每个变量的颜色
|
||||||
|
values = c("out_volumn" = "#000080", "in_volumn" = "#df6100"),
|
||||||
|
# 自定义图例标签, 或者在dataframe里就提前定义好
|
||||||
|
labels = c("out_volumn" = "抽气容积", "in_volumn" = "充气容积")
|
||||||
|
)
|
||||||
|
dev.off()
|
||||||
|
Loading…
Reference in New Issue
Block a user