有谁知道如何从vcd包中将自定义图例添加到fourfold()?
我可以使用legend()函数添加到base中的fourfoldplot()中,但是我想为fourfold()附带的OR≈1.0和OR≠1.0使用自定义颜色
当我使用fourfold()创建图并尝试使用legend()添加图例时,出现以下错误...
strwidth错误(传奇,单位=“用户”,cex = cex,字体= text.font):
plot.new尚未被调用
这是一个例子:
# install.packages("vcd")
library(vcd)
x<-matrix(c(1146,210,471,897,
669,687,809,559,
761,595, 1030,338,
1227,129,1306,62,
844,737,773,370,
1134,447,344,799,
1001,580,790,353,
1461,120,1072,71,
820,837,797,270,
866,791,612,455,
1370,287,421,646,
1583,74,950,117,
1462,1056,155,51,
1349,1169,129,77,
1688,830,103,103,
2419,99,114,92),ncol=8,nrow=8)
x
x<-as.table(x)
x<-as.data.frame(x)
xarray<-array(x$Freq, dim=c(2,2,16))
xarray<-aperm(xarray,c(2,1,3))
dimnames(xarray)[[1]] <- c("No", "Yes")
dimnames(xarray)[[2]] <- c("No", "Yes")
dimnames(xarray)[[3]] <- c("Morning:Morning","Morning:Afternoon","Morning:Evening","Morning:Night-time",
"Afternoon:Morning","Afternoon:Afternoon","Afternoon:Evening","Afternoon:Night-time",
"Evening:Morning","Evening:Afternoon","Evening:Evening","Evening:Night-time",
"Night-time:Morning","Night-time:Afternoon","Night-time:Afternoon","Night-time:Night-time")
names(dimnames(xarray)) <- c("Post", "Pre", "Time of day")
fourfold(xarray, c("#99CCFF", "#6699CC", "#999999", "#E69F00", "#56B4E9", "#009E73"), ticks = 0.25,
main = "Did you usually train in the morning, afternoon, evening or night-time?", p_adjust_method="bon")
legend("right",legend = c("Non Sig.","Sig"), fill = c("#E69F00", "#009E73"))
fourfold
在网格上完成,legend()
不起作用。您可以尝试从VCD使用grid_legend():
library(vcd)
png("test.png",width=800,height=600)
fourfold(xarray, c("#99CCFF", "#6699CC", "#999999", "#E69F00", "#56B4E9", "#009E73"),
ticks = 0.25,
main = "Did you usually train in the morning, afternoon, evening or night-time?",
p_adjust_method="bon")
grid_legend(0.9, 0.5, c(15, 15), c("#E69F00", "#009E73"),
c("Non Sig.","Sig"))
dev.off()
在grid_legend()函数中,前两个参数是x和y,这是图例在绘图设备上的相对位置。因此0.9代表右侧的90%,中间为0.5高度。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句