我正在尝试创建线条图。 我想获得由线图连接的点。 我想根据方法(MET)使用不同的线型(虚线或不使用虚线),并根据变量(Var)使用不同的色线。我有4次(MD)观测值:cd,15、30、45。
我想从左到右添加一个箭头。
这是我的数据库:
> gra
id MD val MET Var
1 1 cd 0.000000 1-KM LRT_DM
2 2 cd 0.000000 CIF LRT_DM
3 3 15 14.740000 1-KM LRT_DM
4 4 15 17.050000 CIF LRT_DM
5 5 30 34.740000 1-KM LRT_DM
6 6 30 35.230000 CIF LRT_DM
7 7 45 55.790000 1-KM LRT_DM
8 8 45 54.550000 CIF LRT_DM
9 1 cd 0.000000 1-KM LRT_HTN
10 2 cd 0.000000 CIF LRT_HTN
11 3 15 6.321839 1-KM LRT_HTN
12 4 15 6.024096 CIF LRT_HTN
13 5 30 13.793103 1-KM LRT_HTN
14 6 30 12.650602 CIF LRT_HTN
15 7 45 36.781609 1-KM LRT_HTN
16 8 45 37.951807 CIF LRT_HTN
17 1 cd 0.000000 1-KM LGIT_DM
18 2 cd 0.000000 CIF LGIT_DM
19 3 15 16.270784 1-KM LGIT_DM
20 4 15 16.206483 CIF LGIT_DM
21 5 30 33.847981 1-KM LGIT_DM
22 6 30 33.253301 CIF LGIT_DM
23 7 45 50.831354 1-KM LGIT_DM
24 8 45 50.060024 CIF LGIT_DM
25 1 cd 0.000000 1-KM LGIT_HTN
26 2 cd 0.000000 CIF LGIT_HTN
27 3 15 5.714286 1-KM LGIT_HTN
28 4 15 5.714286 CIF LGIT_HTN
29 5 30 12.380952 1-KM LGIT_HTN
30 6 30 12.380952 CIF LGIT_HTN
31 7 45 36.190476 1-KM LGIT_HTN
32 8 45 36.190476 CIF LGIT_HTN
33 1 cd 0.000000 1-KM LGITHTN
34 2 cd 0.000000 CIF LGITHTN
35 3 15 15.217391 1-KM LGITHTN
36 4 15 15.217391 CIF LGITHTN
37 5 30 45.652174 1-KM LGITHTN
38 6 30 45.652174 CIF LGITHTN
39 7 45 117.391304 1-KM LGITHTN
40 8 45 117.391304 CIF LGITHTN
41 1 cd 0.000000 1-KM LGUT_DM
42 2 cd 0.000000 CIF LGUT_DM
43 3 15 16.470588 1-KM LGUT_DM
44 4 15 16.867470 CIF LGUT_DM
45 5 30 34.117647 1-KM LGUT_DM
46 6 30 33.734940 CIF LGUT_DM
47 7 45 51.764706 1-KM LGUT_DM
48 8 45 50.602410 CIF LGUT_DM
49 1 cd 0.000000 1-KM LGUT_HTN
50 2 cd 0.000000 CIF LGUT_HTN
51 3 15 5.714286 1-KM LGUT_HTN
52 4 15 5.714286 CIF LGUT_HTN
53 5 30 12.380952 1-KM LGUT_HTN
54 6 30 12.380952 CIF LGUT_HTN
55 7 45 36.190476 1-KM LGUT_HTN
56 8 45 36.190476 CIF LGUT_HTN
这是我的代码:
library(ggplot2)
library(grid)
gra$MD<-factor(gra$MD, levels=c("cd", "15", "30", "45"))
gra$MET<-factor(gra$MET, levels=c("1-KM", "CIF"))
gra$Var<-factor(gra$Var, levels=c("LRT_DM", "LRT_HTN","LGIT_DM", "LGIT_HTN", "LGITHTN", "LGUT_DM" ,"LGUT_HTN"))
ggplot(data=gra, aes(x = gra$MD, y = gra$val, colour = gra$Var)) +geom_line(arrow = arrow())+geom_point()
为什么我没有电话线? 如何添加虚线/非虚线选项? 我已经尝试过了:
ggplot(gra, aes(x = gra$MD, y = gra$val, colour = gra$Var, group= gra$MET)) + geom_line(aes(linetype=gra$MET))+geom_point()
但它不起作用。
谢谢