根据第三个变量绘制线

时间:2019-02-14 05:09:57

标签: r ggplot2 loess

我有以下情节:

enter image description here

其中的点用第三个变量(PC2)进行渐变着色。我想为每组被烧掉的人在第三变量之后添加一行,因此我在下面使用了geom_path: enter image description here

但是,这有点难于理解,我希望对线进行平滑处理,例如使用黄土或直线(但不是 样条线)。我该怎么做?

代码:

cent2 <- data.frame(setkey(as.data.table(cent2), PC2))

ggplot() + theme_classic(base_size = 25)+
  geom_point(data=cent2, aes(x=MD1, y=MD2, colour=PC2, shape=Burnt),size=5,  stroke=2.5)+
  geom_path(data=cent2, inherit.aes = FALSE, aes(x=MD1, y=MD2, colour=PC2, group=Burnt),lwd=2)

数据:

    structure(list(Burnt = c("B", "B", "B", "B", "B", "B", "B", "B", 
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", 
"B", "B", "B", "U", "U", "U", "U", "U", "U"), MD1 = c(0.204867192579801, 
-0.0776919464365632, -0.0985258780184559, -0.0563524339918864, 
-0.168941972265078, -0.0992349984853324, -0.0278298941997196, 
0.0990486018646072, -0.112136116498555, -0.631014366656113, -0.224061303096921, 
-0.0596055517751186, -0.162483830700184, -0.213940650424089, 
-0.324213950145489, -0.441659358945666, 0.153840147757909, 0.245569866545835, 
0.841149191065318, 0.191536819836311, -0.0557241889819188, -0.18779016904373, 
0.0399315515290713, 0.140969916325382, 0.228638192419208, 0.0117789278639977, 
-0.388805366054532, 0.397503432607841, 0.605413187624758, 0.0872397183724941
), MD2 = c(0.372995404279835, -0.37274320011545, -0.252653651894646, 
-0.146171687712726, -0.143751767417655, 0.0784372457212076, 0.329603838864195, 
-0.256441500089685, 0.241578706931834, -0.148691771530893, 0.0352488639544466, 
0.0742867433893977, 0.387038797072594, 0.431314604260312, 0.390447258098939, 
-0.295295754558034, -0.396850670551626, -0.39628319503527, -0.252619429817183, 
-0.37119054323304, 0.2979936019717, 0.63208064055597, 0.186553047195821, 
-0.160499079472323, -0.185294487596355, -0.0271658879275949, 
-0.0527169374456173, 0.00369504610484765, -0.253217306834157, 
0.35005082974105), PC2 = c(-3.90332916476836, -3.0401187135285, 
-2.38225950579012, -1.926913179129, -1.33094610606147, -1.25441628290853, 
-1.24554398786768, -1.16549402421653, -0.85478562595559, -0.533466266916982, 
-0.449057855787371, -0.431063887403239, -0.242317481849106, -0.156157124320658, 
-0.107667254848016, -0.00364367152999789, 0.209486776928627, 
0.277207792179447, 0.435515456675133, 0.756338797211387, 0.959857052349313, 
1.00083196341637, 1.3431666364098, 1.35836865162309, 1.44136036419325, 
1.49102559443091, 1.58873448209872, 1.89695722606769, 2.46542959338715, 
2.61380751631131)), class = "data.frame", row.names = c(NA, -30L
))

0 个答案:

没有答案