简体   繁体   English

从R包标尺修改`pr_curve`和`auc_curve`的数字大小

[英]Modify figure sizes of `pr_curve` and `auc_curve` from R package yardstick

I'm trying to generate ROC curve and precision-recall curve using the library "yardstick". 我正在尝试使用库“标尺”生成ROC曲线和精确回忆曲线。 However, I could not find a way to modify the figure shape. 但是,我找不到修改图形的方法。 Here's a toy example. 这是一个玩具的例子。

## 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()

When you run the codes, the generated figures look like below; 运行代码时,生成的数字如下所示; 在此输入图像描述 在此输入图像描述

The top figure (ROC curve) is in a square form, while the bottom one (precision-recall curve) is a rectangle. 上图(ROC曲线)为方形,而下图(精确回忆曲线)为矩形。

I've tried to 我试过了

  • change width and height options in pdf function 更改pdf函数中的widthheight选项

  • change different options supported by ggplot2 (eg plot.margin using theme ) 更改ggplot2支持的不同选项(例如使用theme plot.margin

but could not find a good way to make two figures in the same shape. 但找不到一个好的方法来制作两个相同形状的数字。

How could I unify their shapes (or forms)? 我怎么能统一他们的形状(或形式)?

Any comment will be very appreciated. 任何评论将非常感激。

coord_fixed() from ggplot2 will do the trick. 来自ggplot2的coord_fixed()可以解决这个问题。 Note that you also need the adapt xlim and ylim if you want the plot area to be a square. 请注意,如果您希望绘图区域为正方形,则还需要使用xlimylim

pr_curve(tmp1, truth = true, pred) %>% 
    autoplot() +
    coord_fixed(xlim = 0:1, ylim = 0:1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM