【问题标题】:Change direction and rotation of a scatterpolar plot in R更改 R 中散点图的方向和旋转
【发布时间】:2021-09-17 22:35:58
【问题描述】:

我有一个数据集,显示相同结构的两次测量值的差异,其中两种不同的方法是距离(米)和方向(度数)。我在 R 中找到了包的函数 plot_ly 的散点图,它几乎产生了我想要的东西,但布局有一些问题。这是我使用的代码:

library(plotly)

data <- data.frame(measurements_compare); data

fig <- plot_ly(
  type = 'scatterpolar',
  r = c(data$distance),
  theta = c(data$rotation),
  text = c(data$id),
  mode = 'markers',
)

fig

我从中得到的是这个情节,这已经很接近我想要的了:

现在我想旋转绘图以使 0° 位于顶部而不是 90°,我还希望将度数绘制为顺时针而不是逆时针上升。我找到了 in the archive 的代码示例,其中使用了函数 update_layout,但此示例使用 Python 而不是 R。我找不到 R 类似的东西,但我很确定一定有。

【问题讨论】:

    标签: r plotly


    【解决方案1】:

    Inn plotly 你可以经常在 R 和 Python 中使用相同的参数。对于您的代码,需要 Rs layout 函数而不是 Python update_layout

    示例数据

    data <- data.frame(distance = sample(seq(.1, .5, by = .01),  15, T),
                       rotation  = sample(0:360, 15, T),
                       id = paste0(1:15))
    

    代码

    fig <- plot_ly(
      type = 'scatterpolar',
      r = c(data$distance),
      theta = c(data$rotation),
      text = c(data$id),
      mode = 'markers',
    ) %>%
      layout(polar = list(
        angularaxis  = list(
          rotation = 90,
          direction = "clockwise"
        )
               ))
    
    fig
    

    剧情

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 2012-10-06
      • 1970-01-01
      相关资源
      最近更新 更多