gpt4 book ai didi

r - 线框:具有多个表面和透明度的图例颜色

转载 作者:行者123 更新时间:2023-12-04 23:58:10 28 4
gpt4 key购买 nike

以下代码使用格子的线框函数绘制了 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")),
)

结果:

enter image description here

谢谢!

最佳答案

要改变线条的颜色,你应该替换 auto.keykey并提供文本和行的值列表。

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")),
)

enter image description here

关于r - 线框:具有多个表面和透明度的图例颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14100494/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com