Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change the default ggplot2 theme produced by autoplot function? #7

Open
Zefeng-Wu opened this issue Apr 26, 2018 · 1 comment
Assignees

Comments

@Zefeng-Wu
Copy link

Zefeng-Wu commented Apr 26, 2018

Hi, there
It is a nice R package. Now, I want to know how to change the plot theme generated by autoplot function, including the text font and size, etc. Moreover, i wand to add the auc score like "AUC=0.9" in the roc curve plot. Thanks

@takayasaito takayasaito self-assigned this Apr 26, 2018
@takayasaito
Copy link
Member

Hi,

The autoplot function of precrec does not return a ggplot object, but you can still use the fortify function to make a data frame for ggplot.

library(precrec)
library(ggplot2)

# Load a dataset with 10 positives and 10 negatives
data(P10N10)

# Generate an sscurve object that contains ROC and Precision-Recall curves
sscurves <- evalmod(scores = P10N10$scores, labels = P10N10$labels)

# Get AUCs
aucs <- auc(sscurves)
df <- data.frame(
  x = 0.5,
  y = 0.5,
  text = paste0("AUC: ",
                as.character(round(aucs[aucs$curvetypes == "ROC",]$aucs, 2)))
)

# Explicitly fortify sscurves
ssdf <- fortify(sscurves)

# Create an ROC plot
p_roc <- ggplot(subset(ssdf, curvetype == "ROC"), aes(x = x, y = y))
p_roc <- p_roc + theme_classic()
p_roc <- p_roc + geom_line()
p_roc <- p_roc + geom_label(data = df, aes(x, y, label = text))
p_roc <- p_roc + ggtitle("ROC")
p_roc <- p_roc + xlab("FPR")
p_roc <- p_roc + ylab("TPR")
p_roc

You can type help("fortify") to see more examples.

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants