22# ' @rdname geom_text
33# ' @param label.padding Amount of padding around label. Defaults to 0.25 lines.
44# ' @param label.r Radius of rounded corners. Defaults to 0.15 lines.
5- # ' @param label.size Size of label border, in mm.
5+ # ' @param label.size `r lifecycle::badge("deprecated")` Replaced by the
6+ # ' `linewidth` aesthetic. Size of label border, in mm.
7+ # ' @param border.colour,border.color Colour of label border. When `NULL`
8+ # ' (default), the `colour` aesthetic determines the colour of the label border.
9+ # ' `border.color` is an alias for `border.colour`.
10+ # ' @param text.colour,text.color Colour of the text. When `NULL` (default), the
11+ # ' `colour` aesthetic determines the colour of the text. `text.color` is an
12+ # ' alias for `text.colour`.
613geom_label <- function (mapping = NULL , data = NULL ,
714 stat = " identity" , position = " nudge" ,
815 ... ,
916 parse = FALSE ,
1017 label.padding = unit(0.25 , " lines" ),
1118 label.r = unit(0.15 , " lines" ),
12- label.size = 0.25 ,
19+ label.size = deprecated(),
20+ border.colour = NULL ,
21+ border.color = NULL ,
22+ text.colour = NULL ,
23+ text.color = NULL ,
1324 size.unit = " mm" ,
1425 na.rm = FALSE ,
1526 show.legend = NA ,
1627 inherit.aes = TRUE ) {
1728
29+ extra_args <- list2(... )
30+ if (lifecycle :: is_present(label.size )) {
31+ deprecate_warn0(" 3.5.0" , " geom_label(label.size)" , " geom_label(linewidth)" )
32+ extra_args $ linewidth <- extra_args $ linewidth %|| % label.size
33+ }
34+
1835 layer(
1936 data = data ,
2037 mapping = mapping ,
@@ -27,10 +44,11 @@ geom_label <- function(mapping = NULL, data = NULL,
2744 parse = parse ,
2845 label.padding = label.padding ,
2946 label.r = label.r ,
30- label.size = label.size ,
3147 size.unit = size.unit ,
48+ border.colour = border.color %|| % border.colour ,
49+ text.colour = text.color %|| % text.colour ,
3250 na.rm = na.rm ,
33- ...
51+ !!! extra_args
3452 )
3553 )
3654}
@@ -49,14 +67,17 @@ GeomLabel <- ggproto("GeomLabel", Geom,
4967 size = from_theme(fontsize ),
5068 angle = 0 ,
5169 hjust = 0.5 , vjust = 0.5 , alpha = NA , fontface = 1 ,
52- lineheight = 1.2
70+ lineheight = 1.2 ,
71+ linewidth = from_theme(borderwidth * 0.5 ),
72+ linetype = from_theme(bordertype )
5373 ),
5474
5575 draw_panel = function (self , data , panel_params , coord , parse = FALSE ,
5676 na.rm = FALSE ,
5777 label.padding = unit(0.25 , " lines" ),
5878 label.r = unit(0.15 , " lines" ),
59- label.size = 0.25 ,
79+ border.colour = NULL ,
80+ text.colour = NULL ,
6081 size.unit = " mm" ) {
6182 lab <- data $ label
6283 if (parse ) {
@@ -71,6 +92,12 @@ GeomLabel <- ggproto("GeomLabel", Geom,
7192 }
7293
7394 size.unit <- resolve_text_unit(size.unit )
95+ data $ text.colour <- text.colour %|| % data $ colour
96+ data $ border.colour <- border.colour %|| % data $ colour
97+ data $ border.colour [data $ linewidth == 0 ] <- NA
98+ data $ fill <- fill_alpha(data $ fill , data $ alpha )
99+ data $ size <- data $ size * size.unit
100+
74101
75102 grobs <- lapply(seq_len(nrow(data )), function (i ) {
76103 row <- data [i , , drop = FALSE ]
@@ -82,16 +109,17 @@ GeomLabel <- ggproto("GeomLabel", Geom,
82109 r = label.r ,
83110 angle = row $ angle ,
84111 text.gp = gg_par(
85- col = row $ colour ,
86- fontsize = row $ size * size.unit ,
112+ col = row $ text. colour ,
113+ fontsize = row $ size ,
87114 fontfamily = row $ family ,
88115 fontface = row $ fontface ,
89116 lineheight = row $ lineheight
90117 ),
91118 rect.gp = gg_par(
92- col = if (isTRUE(all.equal(label.size , 0 ))) NA else row $ colour ,
93- fill = fill_alpha(row $ fill , row $ alpha ),
94- lwd = label.size
119+ col = row $ border.colour ,
120+ fill = row $ fill ,
121+ lwd = row $ linewidth ,
122+ lty = row $ linetype
95123 )
96124 )
97125 })
0 commit comments