【问题标题】:How to plot an ellipse defining the trajectory of planets in R如何绘制定义R中行星轨迹的椭圆
【发布时间】:2021-08-27 17:57:35
【问题描述】:

我有 3 个行星,第一个的偏心率 = 0,70 和半长轴 = 900,第二个偏心率为 0,80 和半长轴 = 1200,第三个偏心率 = 0,90 和半主轴 = 1500。 有没有办法绘制这个?

【问题讨论】:

标签: r plot ellipse


【解决方案1】:

ggforce 包有geom_ellipse。只有一件事,您需要同时提供短轴和长轴,但是从长轴和偏心率很容易计算出短轴。

library(dplyr)
library(ggplot2)
library(ggforce)

planets <- 
  tribble(
    ~e, ~a,
    0.7, 900,
    0.8, 1200,
    0.9, 1500
  ) %>% 
  mutate(name = letters[1:n()]) %>% 
  # calculate minor axis
  mutate(b = a*sqrt(1-e^2)) %>% 
  # centers
  mutate(x0 = 0, y0 = 0)

planets %>% 
  ggplot(aes(color = name)) +
  geom_ellipse(aes(x0 = x0, y0 = y0, a = a, b = b, angle = 0)) +
  coord_fixed()

reprex package (v2.0.1) 于 2021 年 8 月 27 日创建

【讨论】:

    猜你喜欢
    • 2012-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-22
    • 1970-01-01
    • 2015-11-17
    相关资源
    最近更新 更多