如何在canvasxpress Scatter3D的图表中为每个类保持colorBy?

时间:2018-02-09 22:18:11

标签: r htmlwidgets

如何指定固定的colorBy,以使图表中的类相同?例如,如果我在一个页面上有两个图表,并且我想要将setosa红色,彩色蓝色和virginica变为绿色,我将如何提前修复它?我有多个图表,所以每个图表中的类应该是相同的颜色。

# setosa red / versicolor blue
library(canvasXpress)
y=read.table("cX-irist-dat.txt", header=TRUE, sep="\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
z=read.table("cX-irist-var.txt", header=TRUE, sep= "\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE)

fn <- data.frame(cbind(y, Species = z), stringsAsFactors=FALSE)
fn1 <- fn[1:90,]     # first dataset
fn2 <- fn[91:150,]   # second dataset shares 1 class with first


x1 <- fn1[,1:3]
x2 <- subset(fn1,select="Species")

canvasXpress(
  data=x1,
  varAnnot=x2,
  axisTickScaleFontFactor=0.5,
  axisTitleScaleFontFactor=0.5,
  colorBy="Species",
  graphType="Scatter3D",
  title="Iris Data Set",
  xAxis=list("Sepal.Length"),
  yAxis=list("Sepal.Width"),
  zAxis=list("Petal.Length")
)

R canvasxpress iris red/blue colorBy class

# versicolor red should be blue / virginica blue should be green
x3 <- fn2[,1:3]
x4 <- subset(fn2,select="Species")

canvasXpress(
  data=x3,
  varAnnot=x4,
  axisTickScaleFontFactor=0.5,
  axisTitleScaleFontFactor=0.5,
  colorBy="Species",
  graphType="Scatter3D",
  title="Iris Data Set",
  xAxis=list("Sepal.Length"),
  yAxis=list("Sepal.Width"),
  zAxis=list("Petal.Length")
)

R canvasxpress also red/blue colorBy class for different labels

我无法添加标签canvasxpress,但可能应该添加 - 真棒库谢谢!

1 个答案:

答案 0 :(得分:1)

只需将colorKey参数添加到配置中,如下所示:

colorKey = list("Species"=list("setosa"="gold","versicolor"="silver","virginica"="red"))

然后致电:

canvasXpress(
  data=x3,
  varAnnot=x4,
  axisTickScaleFontFactor=0.5,
  axisTitleScaleFontFactor=0.5,
  colorBy="Species",
  graphType="Scatter3D",
  title="Iris Data Set",
  xAxis=list("Sepal.Length"),
  yAxis=list("Sepal.Width"),
  zAxis=list("Petal.Length"),
  colorKey=colorKey
)