我正在用R绘制一个独特类型的分类散点图,其中:
看来,调用“符号”和“符号”会影响色标数以及标记的正确位置。
这是我的演示代码,其中包含hoverinfo,因此您可以看到Top / C的“NA”位置不正确。
library(plotly)
m <- data.frame(c('A','A','B','B','C','C'),
c('Top','Bottom','Top','Bottom','Top','Bottom'),
c('OK','NG','OK','OK','OK','NG'),
c(8,20,55,72,NA,43), # Top,C should be blank
c(4,5,6,7,8,9))
colnames(m) <- c("cat_1","cat_2","check","Bigness", "Twistiness")
color_scale <- list(c(0,'rgb(227,120,0)'),c(0.5,'rgb(220,220,220)') , c(1,'rgb(43,92,138)'))
p <- plot_ly(data = m,
x = ~cat_1,
y = ~cat_2,
type='scatter',
mode='markers',
symbol = ~check, ## problem line
symbols = c('square-open','square'), ## problem line
marker = list(color = ~Twistiness,
size= ~Bigness,
colorscale = color_scale,
colorbar = list(len = 0.8, y = 0.3)),
text = ~paste0('cat_1 (x): ', cat_1, '\n',
'cat_2 (y): ', cat_2, '\n',
'Big (size): ', Bigness, '\n',
'Twist (color): ', Twistiness, '\n')
) %>%
layout(margin = list(r = 8, t = 15, b = 50, l = 80),
# xaxis = list(title = ""),
yaxis = list(title = ""),
showlegend = TRUE)
p
似乎plotly是添加交互式悬停以及将event_data传递给Shiny中另一个代码块的最佳方式。
我通过ggplotly尝试了这个,但event_data不正确,图例不能自定义。