我正在用R绘制在极坐标图中的极坐标图,但是我不希望线间的值被颜色填充。我找到了python库的line_close
属性,但是找不到R中的等效属性。
图表代码:
library(plotly)
p <- plot_ly(
type = 'scatterpolar',
mode = 'lines',
) %>%
add_trace(
mode = 'lines',
r = c(3, 0, 1),
theta = c('A','B','C'),
name = '1'
) %>%
add_trace(
mode = 'lines',
r = c(1, 2, 3),
theta = c('A','B','C'),
name = '2'
) %>%
layout(
polar = list(
radialaxis = list(
angle = 90,
visible = T,
range = c(0,3),
showline = F,
color = '#bfbfbf',
nticks = 4,
tickangle = 90
)
)
)
p
图表图像:
答案 0 :(得分:2)
我对plotly::schema
有了很好的了解,并且似乎没有办法将其内置到plotly
的R端口中。
但是,像这样定义自己的add_closed_trace
函数很简单:
add_closed_trace <- function(p, r, theta, ...)
{
plotly::add_trace(p, r = c(r, r[1]), theta = c(theta, theta[1]), ...)
}
您可以将其用作add_trace
的插件,如下所示:
library(plotly)
p <- plot_ly(
type = 'scatterpolar',
mode = 'lines',
) %>%
add_closed_trace(
mode = 'lines',
r = c(3, 0, 1),
theta = c('A','B','C'),
name = '1'
) %>%
add_closed_trace(
mode = 'lines',
r = c(1, 2, 3),
theta = c('A','B','C'),
name = '2'
) %>%
layout(
polar = list(
radialaxis = list(
angle = 90,
visible = T,
range = c(0,3),
showline = F,
color = '#bfbfbf',
nticks = 4,
tickangle = 90
)
)
)
p