5252# ' @family Themes
5353# ' @section Function ID:
5454# ' 3-10
55- gt_plt_conf_int <- function (gt_object ,
56- column ,
57- ci_columns ,
58- ci = 0.9 ,
59- ref_line = NULL ,
60- palette = c(" black" , " grey" , " white" , " black" ),
61- width = 45 ,
62- text_args = list (accuracy = 1 ),
63- text_size = 1.5 ) {
55+ gt_plt_conf_int <- function (
56+ gt_object ,
57+ column ,
58+ ci_columns ,
59+ ci = 0.9 ,
60+ ref_line = NULL ,
61+ palette = c(" black" , " grey" , " white" , " black" ),
62+ width = 45 ,
63+ text_args = list (accuracy = 1 ),
64+ text_size = 1.5
65+ ) {
6466 all_vals <- gt_index(gt_object , {{ column }}, as_vector = FALSE )
6567
66- stopifnot(" Confidence level must be between 0 and 1" = dplyr :: between(ci , 0 , 1 ))
68+ stopifnot(
69+ " Confidence level must be between 0 and 1" = dplyr :: between(ci , 0 , 1 )
70+ )
6771 # convert desired confidence interval from percentage
6872 # to a two-tailed level to be used in confint() function
6973 level <- 1 - ((1 - ci ) * 2 )
@@ -86,8 +90,10 @@ gt_plt_conf_int <- function(gt_object,
8690
8791 if (" none" %in% ci_val1 ) {
8892 stopifnot(
89- " Must provide list column if no defined Confidence Intervals" =
90- (class(column_vals ) %in% c(" list" ))
93+ " Must provide list column if no defined Confidence Intervals" = (class(
94+ column_vals
95+ ) %in%
96+ c(" list" ))
9197 )
9298
9399 # create a list of dataframes with
@@ -106,8 +112,10 @@ gt_plt_conf_int <- function(gt_object,
106112 })
107113 } else {
108114 stopifnot(
109- " Must provide single values per row if defining Confidence Intervals" =
110- ! (class(column_vals ) %in% " list" )
115+ " Must provide single values per row if defining Confidence Intervals" = ! (class(
116+ column_vals
117+ ) %in%
118+ " list" )
111119 )
112120
113121 data_in <- dplyr :: tibble(mean = column_vals , y = " 1a" ) %> %
@@ -158,7 +166,6 @@ gt_plt_conf_int <- function(gt_object,
158166}
159167
160168
161-
162169# ' Add a confidence interval plot inside a specific row
163170# '
164171# ' @param data_in A dataframe of length 1
@@ -170,13 +177,15 @@ gt_plt_conf_int <- function(gt_object,
170177# ' @noRd
171178# '
172179# ' @return SVG/HTML
173- add_ci_plot <- function (data_in ,
174- pal_vals ,
175- width ,
176- ext_range ,
177- text_args = list (scale_cut = cut_short_scale()),
178- text_size ,
179- ref_line ) {
180+ add_ci_plot <- function (
181+ data_in ,
182+ pal_vals ,
183+ width ,
184+ ext_range ,
185+ text_args = list (scale_cut = cut_short_scale()),
186+ text_size ,
187+ ref_line
188+ ) {
180189 if (NA %in% unlist(data_in )) {
181190 return (" " )
182191 }
@@ -232,12 +241,15 @@ add_ci_plot <- function(data_in,
232241 position = position_nudge(y = 0.25 ),
233242 family = " mono" ,
234243 fontface = " bold" ,
235- label.size = unit( 0 , " lines " ) ,
244+ label.size = 0 ,
236245 label.padding = unit(0.05 , " lines" ),
237246 label.r = unit(0 , " lines" )
238247 ) +
239248 geom_label(
240- aes(x = .data $ ci1 , label = do.call(scales :: label_number , text_args )(.data $ ci1 )),
249+ aes(
250+ x = .data $ ci1 ,
251+ label = do.call(scales :: label_number , text_args )(.data $ ci1 )
252+ ),
241253 position = position_nudge(y = 0.25 ),
242254 color = pal_vals [4 ],
243255 hjust = - 0.1 ,
@@ -246,7 +258,7 @@ add_ci_plot <- function(data_in,
246258 fill = " transparent" ,
247259 family = " mono" ,
248260 fontface = " bold" ,
249- label.size = unit( 0 , " lines " ) ,
261+ label.size = 0 ,
250262 label.padding = unit(0.05 , " lines" ),
251263 label.r = unit(0 , " lines" )
252264 ) +
0 commit comments