gpt4 book ai didi

r - 向情节添加图例

转载 作者:行者123 更新时间:2023-12-05 03:08:03 25 4
gpt4 key购买 nike

如何为位于绘图区域外的以下代码添加图例。这是一个可预测的代码:

par(pty="s")
library(ROCR)
data(ROCR.simple)
pred <- prediction( ROCR.simple$predictions, ROCR.simple$labels )
pred2 <- prediction(abs(ROCR.simple$predictions +
rnorm(length(ROCR.simple$predictions), 0, 0.1)),
ROCR.simple$labels)
perf <- performance(pred, "tpr", "fpr" )
perf2 <- performance(pred2, "tpr", "fpr")
# Plot pred 1
plot(perf, col="red")
# plot pred 2
plot(perf2, add = TRUE, col="blue")

如有任何建议,我们将不胜感激。谢谢!

最佳答案

您可以执行此操作的一种方法是使用 par 来增加顶部的边距,并允许在绘图区域之外进行书写。然后,您可以使用带有负 insetlegend

## Your graph
par(mar=c(5.1,4.1,6,2.1), xpd=TRUE)
plot(perf, col="red")
plot(perf2, add = TRUE, col="blue")

## Add Legend
legend("topright", c("Pred1", "Pred2"), lty=1,
col = c("red", "blue"), bty="n", inset=c(0,-0.15))

Legend in margin

关于r - 向情节添加图例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46186850/

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