首页 > 解决方案 > 在R中绘制雷达图线

问题描述

我在 R 的 plotly 包中创建了下面的雷达图代码。这些线从点到点是笔直的,但我想让它们弯曲。我正在尝试阅读文档以进行绘图,但无法解释。

这是我的代码:

fig <- plot_ly(
    type = 'scatterpolar',
    r = c(1,3,2,4,1),
    theta = c("A","B","C","D","E"),
    fill = 'toself',
    line = list(c(shape = "spline"))
) 
fig %>%
    layout(
        polar = list(
            radialaxis = list(
                visible = T,
                range = c(0,4)
            )
        ),
        showlegend = F
    )

在此处输入图像描述

我希望线条在点处弯曲。

标签: rplotlydata-visualization

解决方案


无需将形状调用封装为矢量。

fig <- plot_ly(
  type = 'scatterpolar',
  mode = "lines+markers",
  r = c(1,3,2,4,1, 1),
  theta = c("A","B","C","D","E", "A"),
  fill = 'toself',
  line = list(shape = 'spline')
) 
fig %>%
  layout(
    polar = list(
      radialaxis = list(
        visible = T,
        range = c(0,4)
      )
    ),
    showlegend = F
  )

在此处输入图像描述

要更改背景和网格线的颜色:

fig <- plot_ly(
  type = 'scatterpolar',
  mode = "lines+markers",
  r = c(1,3,2,4,1, 1),
  theta = c("A","B","C","D","E", "A"),
  fill = 'toself',
  line = list(shape = 'spline')
) 
fig %>%
  layout(
    polar = list(
      bgcolor = "yellow",
      radialaxis = list(
        visible = T,
        range = c(0,4),
        gridcolor = "blue",
        linecolor = "red"),
      angularaxis = list(
        linecolor = "darkgreen")
    ),
    showlegend = F

  )

在此处输入图像描述


推荐阅读