Skip to content

Commit

Permalink
Functional Update
Browse files Browse the repository at this point in the history
  • Loading branch information
samueltobler committed Jan 30, 2024
1 parent 09da940 commit 15e7b8e
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 0 deletions.
41 changes: 41 additions & 0 deletions R/confidence_plot.groups.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
overconfidence_plot.groups <- function(data, color = blue, plot = "jitter", colorbg = blue202, name = "", export = FALSE, group) {

require(ggplot2)
require(ggpubr)
require(RColorBrewer)

df <- data.frame(Score = data, Class = "", Group = group)

if(plot == "jitter") {

bxp <- ggplot(df, aes(y = Score, color = Group, x = Group), ylim = c(0,1)) +
geom_hline(yintercept = c(0.2,0.5, 0.8), color = "black", size = 0.5, linetype = "dashed") +
geom_hline(yintercept = c(0,1), color = "black", size = 0.5, linetype="dashed") +
geom_violin(aes(fill = Group), width = 0.8) +
geom_boxplot(width=0.4, position = position_dodge(width=0.9), )+
scale_color_manual(values = c("black", "black", "black"))+
scale_fill_manual(values = c(rgb(0.95, 0.95, 0.95),
rgb(0.95, 0.95, 0.95),
rgb(0.95, 0.95, 0.95)), name = "")+
theme(strip.text.y = element_text(angle = 0),
axis.ticks.x = element_blank())

bxp1 <- bxp + theme_pubr()+
theme(legend.position = "none", axis.ticks.x = element_blank()) +
xlab("")+
ylab("Overconfidence Score")+
scale_y_continuous(breaks = c(0, 0.2, 0.5, 0.8, 1), limits = c(0,1)) +
guides(fill=guide_legend(title=""), color = "none") +
geom_jitter(color=color, size=3, alpha=0.5, width = 0.25)

}

if (export == TRUE) {
name <- paste(name,".pdf", sep = "")
ggsave(name, bxp1, width = 10, height = 6)
}

return(bxp1)


}
34 changes: 34 additions & 0 deletions R/miscalibration_plot.groups.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
miscalibration_plot.groups <- function(miscalibration, calibrationaccuracy,
export = FALSE, name = "", group) {

require(ggplot2)
require(ggpubr)
require(RColorBrewer)

grey95 <- rgb(0.95, 0.95, 0.95)

dfx <- data.frame(Score = miscalibration, Class = "", accuracy = calibrationaccuracy, Group = group)

t1 <- ggplot(dfx, aes(x = Group, y = Score), ylim = c(-1,1)) +
geom_hline(yintercept = 0, color = "black", size = 0.5, linetype = "dashed")+
geom_violin(aes(fill = Group), fill = grey95) +#facet_wrap(~Group)+
geom_boxplot(width = 0.3) +
geom_jitter(width = 0.25, size = 3, aes(color = accuracy), alpha = 0.9)+
scale_color_gradient(low = "red", high = green, limits = c(0,1),
name = "Calibration \nAccuracy\n") +
theme_pubr(legend = "right")+
xlab("")+
scale_y_continuous(breaks = c(-1, -0.5, 0, 0.5, 1), limits = c(-1, 1))+
ylab("Miscalibration Score")+
theme(strip.text.y = element_text(angle = 0), axis.ticks.x = element_blank())


if (export == TRUE) {
name <- paste(name,".pdf", sep = "")
ggsave(name, t1, width = 10, height = 6)
}


return(t1)

}
41 changes: 41 additions & 0 deletions R/overconfidence_plot.groups.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
overconfidence_plot.groups <- function(data, color = blue, plot = "jitter", colorbg = blue202, name = "", export = FALSE, group) {

require(ggplot2)
require(ggpubr)
require(RColorBrewer)

df <- data.frame(Score = data, Class = "", Group = group)

if(plot == "jitter") {

bxp <- ggplot(df, aes(y = Score, color = Group, x = Group), ylim = c(0,1)) +
geom_hline(yintercept = c(0.2,0.5, 0.8), color = "black", size = 0.5, linetype = "dashed") +
geom_hline(yintercept = c(0,1), color = "black", size = 0.5, linetype="dashed") +
geom_violin(aes(fill = Group), width = 0.8) +
geom_boxplot(width=0.4, position = position_dodge(width=0.9), )+
scale_color_manual(values = c("black", "black", "black"))+
scale_fill_manual(values = c(rgb(0.95, 0.95, 0.95),
rgb(0.95, 0.95, 0.95),
rgb(0.95, 0.95, 0.95)), name = "")+
theme(strip.text.y = element_text(angle = 0),
axis.ticks.x = element_blank())

bxp1 <- bxp + theme_pubr()+
theme(legend.position = "none", axis.ticks.x = element_blank()) +
xlab("")+
ylab("Overconfidence Score")+
scale_y_continuous(breaks = c(0, 0.2, 0.5, 0.8, 1), limits = c(0,1)) +
guides(fill=guide_legend(title=""), color = "none") +
geom_jitter(color=color, size=3, alpha=0.5, width = 0.25)

}

if (export == TRUE) {
name <- paste(name,".pdf", sep = "")
ggsave(name, bxp1, width = 10, height = 6)
}

return(bxp1)


}
41 changes: 41 additions & 0 deletions R/underconfidence_plot.groups.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
underconfidence_plot.groups <- function(data, color = blue, plot = "jitter", colorbg = blue202, name = "", export = FALSE, group) {

require(ggplot2)
require(ggpubr)
require(RColorBrewer)

df <- data.frame(Score = data, Class = "", Group = group)

if(plot == "jitter") {

bxp <- ggplot(df, aes(y = Score, color = Group, x = Group), ylim = c(0,1)) +
geom_hline(yintercept = c(0.2,0.5, 0.8), color = "black", size = 0.5, linetype = "dashed") +
geom_hline(yintercept = c(0,1), color = "black", size = 0.5, linetype="dashed") +
geom_violin(aes(fill = Group), width = 0.8) +
geom_boxplot(width=0.4, position = position_dodge(width=0.9), )+
scale_color_manual(values = c("black", "black", "black"))+
scale_fill_manual(values = c(rgb(0.95, 0.95, 0.95),
rgb(0.95, 0.95, 0.95),
rgb(0.95, 0.95, 0.95)), name = "")+
theme(strip.text.y = element_text(angle = 0),
axis.ticks.x = element_blank())

bxp1 <- bxp + theme_pubr()+
theme(legend.position = "none", axis.ticks.x = element_blank()) +
xlab("")+
ylab("Underconfidence Score")+
scale_y_continuous(breaks = c(0, 0.2, 0.5, 0.8, 1), limits = c(0,1)) +
guides(fill=guide_legend(title=""), color = "none") +
geom_jitter(color=color, size=3, alpha=0.5, width = 0.25)

}

if (export == TRUE) {
name <- paste(name,".pdf", sep = "")
ggsave(name, bxp1, width = 10, height = 6)
}

return(bxp1)


}

0 comments on commit 15e7b8e

Please sign in to comment.