4

次のコードは、ラティスのワイヤーフレーム関数を使用して3つの色付きの平面をプロットします。しかし、カラーグループを設定しても凡例が変わらない理由がわかりません。手動でやろうとしましたが、テキストの色を変更するだけでした。ちなみに、表面を70%透明にする方法も知っている人はいますか?

library(lattice)
library(akima)

SurfaceData <- data.frame(
               x=rep(seq(0,100,length.out=10),each=10,times=3),
               y=rep(rep(seq(0,100,length.out=10),times=10),times=3),
               z=c(rep(25,100),seq(30,70,length.out=100),seq(95,75,length.out=100)),
               type=factor(rep(c("A","B","C"),each=100))
                          )

wireframe(z~x*y,data=SurfaceData,group=type,
          col.groups=c("red","green","blue"),
          scales = list(arrows=FALSE, col="black",font=10),
          xlab = list("Variable X",rot=30),
          ylab = list("Variable Y",rot=-30),
          zlab = list("Variable Z",rot=90),
          zlim = c(0,100),
          #auto.key=TRUE,
          auto.key=list(text=c("A","B","C"),col=c("red","green","blue"),lines=TRUE),
          par.settings = list(axis.line = list(col = "transparent")),
          )

結果:

ここに画像の説明を入力してください

ありがとうございました!

4

2 に答える 2

6

行の色を変更するには、テキストと行の値のリストを置き換えauto.keyて指定する必要があります。key

wireframe(z~x*y,data=SurfaceData,group=type,
          col.groups=c("red","green","blue"),
          scales = list(arrows=FALSE, col="black",font=10),
          xlab = list("Variable X",rot=30),
          ylab = list("Variable Y",rot=-30),
          zlab = list("Variable Z",rot=90),
          zlim = c(0,100),
          key=list(text=list(c("A","B","C"),col=c("red","green","blue")),
                   lines=list(lty=c(1,1,1),col=c("red","green","blue"))),
          par.settings = list(axis.line = list(col = "transparent")),
)

色を透明にするには、関数を使用できますrgb()mycolors.transここでは、透明な色を含みmycolors、同じ色であるが凡例エントリに対しては透明ではない新しい変数を定義します。

mycolors.trans = rgb(c(255,0,0), 
               c(0,255,0), 
               c(0,0,255),alpha = 70,maxColorValue = 255) 

mycolors = rgb(c(255,0,0), 
                     c(0,255,0), 
                     c(0,0,255),maxColorValue = 255) 

wireframe(z~x*y,data=SurfaceData,group=type,
          col.groups=mycolors.trans,
          scales = list(arrows=FALSE, col="black",font=10),
          xlab = list("Variable X",rot=30),
          ylab = list("Variable Y",rot=-30),
          zlab = list("Variable Z",rot=90),
          zlim = c(0,100),
          #auto.key=TRUE,
          key=list(text=list(c("A","B","C"),col=mycolors),
                   lines=list(lty=c(1,1,1),col=mycolors)),
          par.settings = list(axis.line = list(col = "transparent")),
)

ここに画像の説明を入力してください

于 2012-12-31T11:07:37.633 に答える
1

見る ?simpleTheme、透明部分用

    par.settings =  simpleTheme(alpha = 0.7)
于 2012-12-31T11:21:24.830 に答える