简体   繁体   English

如何创建一个在 R 中绘制径向线的函数?

[英]How to create a function that plots radials in R?

I have never plotted a radial in R before, so I have no idea what I am doing.我以前从未在 R 中绘制过径向线,所以我不知道我在做什么。 Is there a different type of plot I should be using?我应该使用不同类型的绘图吗? Also I have a list of r's and theta's, however I am not sure how to create a loop in order to transform them all to Cartesian coordinates?我还有一个 r 和 theta 的列表,但是我不确定如何创建一个循环以将它们全部转换为笛卡尔坐标?

Data数据

"theta","r"
0,4
0.31,2.07
0.63,2.15
0.94,3.08
1.26,4.09
1.57,2.39
1.88,1.96
2.2,3.72
2.51,4.72
2.83,2.87
3.14,1.67
3.46,3.51
3.77,4.37
4.08,2.24
4.4,2.23
4.71,4.18
5.03,3.12
5.34,2.67
5.65,2.19
5.97,3.16

The ggplot2 package allows for plotting in polar coordinates quite conveniently: ggplot2包允许非常方便地在极坐标中绘图:

library(ggplot2)
ggplot(DF, aes(theta, r)) +
  geom_line() +
  coord_polar()
  

在此处输入图片说明

coord_polar() does all the transformation. coord_polar()完成所有转换。

Data数据

DF <- data.table::fread("theta,r
                  0,4
                  0.31,2.07
                  0.63,2.15
                  0.94,3.08
                  1.26,4.09
                  1.57,2.39
                  1.88,1.96
                  2.2,3.72
                  2.51,4.72
                  2.83,2.87
                  3.14,1.67
                  3.46,3.51
                  3.77,4.37
                  4.08,2.24
                  4.4,2.23
                  4.71,4.18
                  5.03,3.12
                  5.34,2.67
                  5.65,2.19
                  5.97,3.16")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM