@@ -1142,10 +1142,10 @@ get_plot_avg_rel_skill_by_t <- function(scores_obj,
11421142 ) +
11431143 labs(
11441144 x = " " ,
1145- y = glue :: glue(" Relative scaled\n skill ({label})" )
1145+ y = glue :: glue(" Average relative scaled\n skill ({label})" )
11461146 ) +
11471147 scale_y_continuous(trans = " log10" ) +
1148- coord_cartesian(ylim = c(1 / 2.4 , 2.4 )) +
1148+ coord_cartesian(ylim = c(1 / 3 , 3 )) +
11491149 theme(
11501150 axis.text.x = element_blank(),
11511151 axis.title.x = element_text(size = 12 )
@@ -1163,3 +1163,108 @@ get_plot_avg_rel_skill_by_t <- function(scores_obj,
11631163 }
11641164 return (p )
11651165}
1166+
1167+ # ' Brier/Energy Relative skill averaged by model
1168+ # '
1169+ # ' @param scores_obj Scoringutils scores object
1170+ # ' @param score_type Character string indicating which score metric to use
1171+ # ' @param remove_legend Boolean indicating whether to keep legend, default
1172+ # ' is TRUE.
1173+ # ' @param add_shape Boolean indicating whether to add the shape legend,
1174+ # ' default is FALSE.
1175+ # ' @param title Character string indicating title, default is NULL.
1176+ # ' @importFrom scoringutils summarise_scores
1177+ # ' @importFrom ggplot2 ggplot geom_bar aes geom_hline coord_flip
1178+ # ' @importFrom rlang sym
1179+ # ' @returns ggplot object
1180+ # ' @autoglobal
1181+ get_plot_avg_rel_skill_overall <- function (scores_obj ,
1182+ score_type = c(" brier_score" , " energy_score" ),
1183+ remove_legend = TRUE ,
1184+ add_shape = FALSE ,
1185+ title = NULL ) {
1186+ score_type <- rlang :: arg_match(score_type )
1187+ plot_components_list <- plot_components()
1188+ if (score_type == " brier_score" ) {
1189+ label <- " Brier score"
1190+ } else {
1191+ label <- " Energy score"
1192+ }
1193+
1194+ rel_skill <- scores_obj | >
1195+ ungroup() | >
1196+ filter(! is.na(!! sym(score_type ))) | >
1197+ scoringutils :: get_pairwise_comparisons(
1198+ baseline = " Hub-baseline" ,
1199+ metric = score_type ,
1200+ by = c(" nowcast_date" , " target_date" , " location" )
1201+ ) | >
1202+ filter(model != " Hub-baseline" ) | >
1203+ group_by(model ) | >
1204+ summarise(scaled_rel_skill = mean(!! sym(glue :: glue(
1205+ " {score_type}_scaled_relative_skill"
1206+ )), na.rm = TRUE ))
1207+
1208+ p <- ggplot(rel_skill ) +
1209+ geom_point(
1210+ aes(
1211+ x = model ,
1212+ y = scaled_rel_skill ,
1213+ color = model ,
1214+ shape = model
1215+ ),
1216+ size = 6
1217+ ) +
1218+ geom_hline(yintercept = 1 , linetype = " dashed" , color = " gray50" ) +
1219+ scale_color_manual(
1220+ name = " Model" ,
1221+ values = plot_components_list $ model_colors
1222+ ) +
1223+ scale_shape_manual(
1224+ name = " Model" ,
1225+ values = plot_components_list $ model_shapes
1226+ ) +
1227+ get_plot_theme() +
1228+ labs(
1229+ x = " " ,
1230+ y = glue :: glue(" Average relative scaled skill\n ({label})" )
1231+ ) +
1232+ scale_y_continuous(trans = " log10" ) +
1233+ theme(
1234+ axis.text.x = element_blank(),
1235+ axis.ticks.x = element_blank()
1236+ ) +
1237+ coord_cartesian(ylim = c(1 / 1.3 , 1.3 )) +
1238+ guides(
1239+ color = guide_legend(
1240+ title.position = " top" ,
1241+ nrow = 1
1242+ ),
1243+ shape = guide_legend(
1244+ title.position = " top" ,
1245+ nrow = 1
1246+ )
1247+ )
1248+
1249+ if (isTRUE(remove_legend )) {
1250+ p <- p + guides(
1251+ fill = " none" ,
1252+ color = " none" ,
1253+ shape = " none"
1254+ )
1255+ }
1256+
1257+ if (isTRUE(add_shape )) {
1258+ p <- p + guides(
1259+ shape = guide_legend(
1260+ title.position = " top" ,
1261+ nrow = 1
1262+ )
1263+ )
1264+ }
1265+
1266+ if (! is.null(title )) {
1267+ p <- p + ggtitle(glue :: glue(" {title}" ))
1268+ }
1269+ return (p )
1270+ }
0 commit comments