gpt4 book ai didi

r - 更改在 plotly 中创建的雷达图中特定环的颜色

转载 作者:行者123 更新时间:2023-12-04 17:17:33 27 4
gpt4 key购买 nike

我有一个雷达图,如下所示。有没有一种方法可以让只有 100 的戒指是红色的,而所有其他戒指都保持灰白色?

enter image description here

library(plotly)

fig <- plot_ly(
type = 'scatterpolar',
r = c(135, 75, 110),
theta = c('A','B','C'),
fill = 'toself'
)
fig %>%
layout(
polar = list(
radialaxis = list(
visible = T,
range = c(0, 150)
)
)
)

最佳答案

据我所知,除了零之外,没有在任何轴线上使用自定义格式的选项,因此这里可能实际上没有您希望的“规范”答案。

话虽如此,向您的绘图添加另一条轨迹可能是最好的解决方法,即使它有点笨拙。因为添加的线轨迹覆盖了默认的分类轴,一些更广泛的角轴定制和一些数学手动计算相对于 360 度坐标系的分类值(这通常对用户来说是模糊的)是需要。

Names <- c('A','B','C')
Values <- c(135, 75, 110)
ThetaValues <- seq(from = 0, to = 360, length.out = length(Values)+1L)[seq_len(length(Values - 1L))]

plot_ly() %>%
add_trace(type = 'scatterpolar',mode = "lines",
r = rep(100,100),
theta = seq(from = 0, to = 360, length.out = 100),
line = list(smoothing = 1,
color = "red",
shape = "spline"),
hoverinfo = "skip",
showlegend = FALSE) %>%
add_trace(type = 'scatterpolar',mode = "markers",
r = Values,
name = "",
theta = ThetaValues,
color = I("blue"),
fill = 'toself') %>%
layout(polar = list(radialaxis = list(visible = T,
range = c(0, 150)),
angularaxis = list(visible = T,
type = "category",
ticktext = Names,
tickvals = ThetaValues)))

Polar Chart

关于r - 更改在 plotly 中创建的雷达图中特定环的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68304258/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com