简体   繁体   中英

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". 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.

I've tried to

  • change width and height options in pdf function

  • change different options supported by ggplot2 (eg plot.margin using theme )

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. Note that you also need the adapt xlim and ylim if you want the plot area to be a square.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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