Plotly scatterternary-具有连续色彩美学的问题

问题描述 投票:0回答:1

我在使用Plotly在R中创建三元图时发现了一个问题。如果颜色美感是连续变量,则三元图似乎在背景中具有二元图。离散的颜色美学效果很好。有人知道解决方法吗?

library(tidyverse)
library(plotly)



# Make a dataframe

df<-data.frame(ID = 1:6,
                ID2 = c(rep("B14",4),"B16","B16"),
                Location = c(40.9,96,120,308.5,322,420),
                Classifier = c(rep("A",3),rep("B",3)),
                A = c(0.06,0.06,0.02,0.02,0.01,0.01),
                B = c(0.04,0.01,0.03,0.04,0.02,0.06),
                C= c(0.26,0.06,0.43,0.35,0.29,0.74),
                X = c(363,696,757,1650,609,392)
                )

具有不连续颜色的三元示例

# Colours by discrete variable work fine 

df %>% 
  plot_ly(
    a = ~A,
    b = ~B,
    c = ~C,
    text = ~ID,
    color = ~Classifier,
    colors = "Set1",
    type = 'scatterternary',
    mode = 'markers',
    marker = list( 
      symbol ='circle',
      opacity = 0.6,
      size = 15
    )) 

连续变量的颜色在三进制的背景中创建了两个附加轴。

df %>% 
  plot_ly(
    a = ~A,
    b = ~B,
    c = ~C,
    text = ~ID,
    color = ~X,
    colors = "Spectral",
    type = 'scatterternary',
    mode = 'markers',
    marker = list( 
      symbol ='circle',
      opacity = 0.6,
      size = 15
    )) 

enter image description here

r plotly r-plotly
1个回答
1
投票

这不是解决方法-更像是掩盖了问题。您可以像这样隐藏x和y轴:

ax <- list(
  title = "",
  zeroline = FALSE,
  showline = FALSE,
  showticklabels = FALSE,
  showgrid = FALSE
)

# use your df:
df %>% 
  plot_ly(
    a = ~A,
    b = ~B,
    c = ~C,
    text = ~ID,
    color = ~X,
    colors = "Spectral",
    type = 'scatterternary',
    mode = 'markers',
    marker = list( 
      symbol ='circle',
      opacity = 0.6,
      size = 15
    )) %>%
  layout(xaxis = ax, yaxis = ax)
© www.soinside.com 2019 - 2024. All rights reserved.