r - Plotly scatterternary - 连续色彩美学的问题
问题描述
在 R 中使用 plotly 创建三元图时,我发现了一个问题。如果颜色美学是一个连续变量,则三元图在背景中似乎有一个二元图。离散的色彩美学似乎效果很好。有人知道修复吗?
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
))
解决方案
这不是解决办法——更多的是解决问题的面具。您可以像这样隐藏 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)
推荐阅读
- reactjs - 在 react-routing 上渲染一个新页面,但它会在当前页面内渲染它
- r - 在 R 中的 dplyr 管道中迭代总结
- javascript - 访问
- reactjs - 导出相同命名的接口和变量时打字稿中的奇怪行为
- javascript - aframe 不渲染映射到画布的 lottie json 纹理,但在 three.js 中工作
- python - 使用 spaCy 3 进行自定义 NER 训练会引发 ValueError
- java - 添加垂直滚动条 java swing netbeans
- npm - npm audit fix --force 不能解决问题
- azure - 多阶段 yaml 的一部分可以归类为发布管道吗?
- c# - 上传多个 excel 文件 ASP.NET