如何在ggplot2中使用两个向量绘制闭合线?

问题描述 投票:1回答:1

我有4个时间序列。每个都有两个向量,表示极坐标中的时间序列,作为一系列数字。第一个数字在最后重复,以便关闭这些行:

> scn.x<-c(0.1621270, 0.1567967, 0.1685343, 0.1616781, 0.1719916, 0.1608374, 0.1823657, 0.1934863, 0.2225557, 0.2649875, 0.2363328, 0.1969804, 0.1394642, 0.2354821, 0.3667378, 0.4565170, 0.5321391, 0.6184038, 0.6061903, 0.5454402, 0.4960434, 0.4622253, 0.4038907, 0.3596160, 0.3481931, 0.3162522, 0.2722557 ,0.2242892, 0.1813745, 0.2354114, ,0.2606156, 0.3853444, 0.5376797, 0.5730340, 0.6489497, 0.5288091, 0.3917589,0.2886900, 0.1989709, 0.1574723, 0.1423745, 0.1212815, 0.1268479, 0.1169251, 0.1307069, 0.1349940, 0.1390822, 0.1448997 ,0.1570968, 0.1592046, 0.1578458, 0.1950853 ,0.2288536, 0.2725137)
> 
> i<-c(1:length(scn.x)) ai.scn.x<-scn.x*cos((2*pi*i)/length(scn.x))
> oi.scn.x<-scn.x*sin((2*pi*i)/length(scn.x))
> ai.scn.x<-append(ai.scn.x,ai.scn.x[1])
> oi.scn.x<-append(oi.scn.x,oi.scn.x[1])

所以使用正常的情节,我有这个:

enter image description here

我怎么做,使用ggplot2?

r ggplot2
1个回答
3
投票

使用geom_path,它按照它出现的顺序绘制数据,而不是按x值的大小顺序绘制。

library(ggplot2)

ggplot(data.frame(ai.scn.x, oi.scn.x), aes(ai.scn.x, oi.scn.x)) +
  geom_path() +
  theme_bw()

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.