我正在尝试使用库“yardstick”生成 ROC 曲线和精确召回曲线。但是,我找不到修改图形形状的方法。这是一个玩具示例。
## Precision-recall curve
data.frame(true = as.factor(rep(c(0,1), 10)),
pred = runif(20)) %>%
pr_curve(truth = true, pred) %>%
autoplot()
## ROC curve
data.frame(true = as.factor(rep(c(0,1), 10)),
pred = runif(20)) %>%
roc_curve(truth = true, pred) %>%
autoplot()
上图(ROC 曲线)是正方形,而下图(准确率-召回曲线)是矩形。
我试过了
更改
pdf
函数中的width
和height
选项更改 ggplot2 支持的不同选项(例如
plot.margin
使用theme
)
但找不到使两个图形形状相同的好方法。
我怎样才能统一它们的形状(或形式)?
任何意见将不胜感激。
最佳答案
来自 ggplot2 的
coord_fixed()
可以解决问题。请注意,如果您希望绘图区域为正方形,您还需要适应 xlim
和 ylim
。
pr_curve(tmp1, truth = true, pred) %>%
autoplot() +
coord_fixed(xlim = 0:1, ylim = 0:1)
关于r - 从 R 包标准修改 `pr_curve` 和 `auc_curve` 的图形大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57213959/