@@ -387,9 +387,11 @@ to_basic.GeomHex <- function(data, prestats_data, layout, params, p, ...) {
387
387
dy <- resolution(data [[" y" ]], FALSE )/ sqrt(3 )/ 2 * 1.15
388
388
hexC <- hexbin :: hexcoords(dx , dy , n = 1 )
389
389
n <- nrow(data )
390
- data $ size <- ifelse(data $ size < 1 , data $ size ^ (1 / 6 ), data $ size ^ 6 )
391
- x <- rep.int(hexC [[" x" ]], n ) * rep(data $ size , each = 6 ) + rep(data [[" x" ]], each = 6 )
392
- y <- rep.int(hexC [[" y" ]], n ) * rep(data $ size , each = 6 ) + rep(data [[" y" ]], each = 6 )
390
+ nm <- linewidth_or_size(GeomHex )
391
+ size <- data [[nm ]]
392
+ data [[nm ]] <- ifelse(size < 1 , size ^ (1 / 6 ), size ^ 6 )
393
+ x <- rep.int(hexC [[" x" ]], n ) * rep(data [[nm ]], each = 6 ) + rep(data [[" x" ]], each = 6 )
394
+ y <- rep.int(hexC [[" y" ]], n ) * rep(data [[nm ]], each = 6 ) + rep(data [[" y" ]], each = 6 )
393
395
data <- data [rep(seq_len(n ), each = 6 ), ]
394
396
data [[" x" ]] <- x
395
397
data [[" y" ]] <- y
@@ -558,13 +560,15 @@ to_basic.GeomSpoke <- function(data, prestats_data, layout, params, p, ...) {
558
560
# ' @export
559
561
to_basic.GeomCrossbar <- function (data , prestats_data , layout , params , p , ... ) {
560
562
# from GeomCrossbar$draw_panel()
561
- middle <- base :: transform(data , x = xmin , xend = xmax , yend = y , size = size * params $ fatten , alpha = NA )
563
+ middle <- base :: transform(data , x = xmin , xend = xmax , yend = y , alpha = NA )
564
+ nm <- linewidth_or_size(GeomCrossbar )
565
+ data [[nm ]] <- data [[nm ]] * params $ fatten
562
566
list (
563
567
prefix_class(to_basic.GeomRect(data ), " GeomCrossbar" ),
564
568
prefix_class(to_basic.GeomSegment(middle ), " GeomCrossbar" )
565
569
)
566
570
}
567
- utils :: globalVariables(c(" xmin" , " xmax" , " y" , " size" , " COL" , " PANEL" , " ROW" , " yaxis" ))
571
+ utils :: globalVariables(c(" xmin" , " xmax" , " y" , " size" , " linewidth " , " COL" , " PANEL" , " ROW" , " yaxis" ))
568
572
569
573
# ' @export
570
574
to_basic.GeomRug <- function (data , prestats_data , layout , params , p , ... ) {
@@ -710,7 +714,7 @@ geom2trace.GeomPath <- function(data, params, p) {
710
714
name = if (inherits(data , " GeomSmooth" )) " fitted values" ,
711
715
line = list (
712
716
# TODO: line width array? -- https://github.com/plotly/plotly.js/issues/147
713
- width = aes2plotly(data , params , " size " )[1 ],
717
+ width = aes2plotly(data , params , linewidth_or_size( GeomPath ) )[1 ],
714
718
color = toRGB(
715
719
aes2plotly(data , params , " colour" ),
716
720
aes2plotly(data , params , " alpha" )
@@ -803,7 +807,7 @@ geom2trace.GeomBar <- function(data, params, p) {
803
807
aes2plotly(data , params , " alpha" )
804
808
),
805
809
line = list (
806
- width = aes2plotly(data , params , " size " ),
810
+ width = aes2plotly(data , params , linewidth_or_size( GeomBar ) ),
807
811
color = aes2plotly(data , params , " colour" )
808
812
)
809
813
)
@@ -812,7 +816,7 @@ geom2trace.GeomBar <- function(data, params, p) {
812
816
813
817
# ' @export
814
818
geom2trace.GeomPolygon <- function (data , params , p ) {
815
-
819
+
816
820
data <- group2NA(data )
817
821
818
822
L <- list (
@@ -826,7 +830,7 @@ geom2trace.GeomPolygon <- function(data, params, p) {
826
830
type = " scatter" ,
827
831
mode = " lines" ,
828
832
line = list (
829
- width = aes2plotly(data , params , " size " ),
833
+ width = aes2plotly(data , params , linewidth_or_size( GeomPolygon ) ),
830
834
color = toRGB(
831
835
aes2plotly(data , params , " colour" ),
832
836
aes2plotly(data , params , " alpha" )
@@ -873,7 +877,7 @@ geom2trace.GeomBoxplot <- function(data, params, p) {
873
877
),
874
878
line = list (
875
879
color = aes2plotly(data , params , " colour" ),
876
- width = aes2plotly(data , params , " size " )
880
+ width = aes2plotly(data , params , linewidth_or_size( GeomBoxplot ) )
877
881
)
878
882
))
879
883
}
@@ -976,11 +980,11 @@ geom2trace.default <- function(data, params, p) {
976
980
# since plotly.js can't draw two polygons with different fill in a single trace
977
981
split_on <- function (dat ) {
978
982
lookup <- list (
979
- GeomHline = c(" linetype" , " colour" , " size" ),
980
- GeomVline = c(" linetype" , " colour" , " size" ),
981
- GeomAbline = c(" linetype" , " colour" , " size" ),
982
- GeomPath = c(" fill" , " colour" , " size" ),
983
- GeomPolygon = c(" fill" , " colour" , " size" ),
983
+ GeomHline = c(" linetype" , " colour" , " size" , " linewidth " ),
984
+ GeomVline = c(" linetype" , " colour" , " size" , " linewidth " ),
985
+ GeomAbline = c(" linetype" , " colour" , " size" , " linewidth " ),
986
+ GeomPath = c(" fill" , " colour" , " size" , " linewidth " ),
987
+ GeomPolygon = c(" fill" , " colour" , " size" , " linewidth " ),
984
988
GeomBar = " fill" ,
985
989
GeomBoxplot = c(" colour" , " fill" , " size" ),
986
990
GeomErrorbar = " colour" ,
@@ -1079,7 +1083,7 @@ aes2plotly <- function(data, params, aes = "size") {
1079
1083
# Hack to support this geom_sf hack
1080
1084
# https://github.com/tidyverse/ggplot2/blob/505e4bfb/R/sf.R#L179-L187
1081
1085
defaults <- if (inherits(data , " GeomSf" )) {
1082
- type <- if (any(grepl(" point " , class(data )))) " point" else if (any(grepl(" line " , class(data )))) " line" else " "
1086
+ type <- if (any(grepl(" [P-p]oint " , class(data )))) " point" else if (any(grepl(" [L-l]ine " , class(data )))) " line" else " "
1083
1087
ggfun(" default_aesthetics" )(type )
1084
1088
} else {
1085
1089
geom_obj <- ggfun(geom )
@@ -1093,7 +1097,8 @@ aes2plotly <- function(data, params, aes = "size") {
1093
1097
vals <- uniq(data [[aes ]]) %|| % params [[aes ]] %|| % defaults [[aes ]] %|| % NA
1094
1098
converter <- switch (
1095
1099
aes ,
1096
- size = mm2pixels ,
1100
+ size = mm2pixels ,
1101
+ linewidth = mm2pixels ,
1097
1102
stroke = mm2pixels ,
1098
1103
colour = toRGB ,
1099
1104
fill = toRGB ,
@@ -1112,6 +1117,26 @@ aes2plotly <- function(data, params, aes = "size") {
1112
1117
converter(vals )
1113
1118
}
1114
1119
1120
+
1121
+ # ggplot2 3.4.0 deprecated size in favor of linewidth in line-based geoms (e.g.,
1122
+ # GeomLine, GeomRect, etc) and elements (e.g., element_line(), element_rect(),
1123
+ # etc). Note that, some geoms (e.g., GeomBoxplot, GeomSf) can have both
1124
+ # linewidth and size
1125
+ linewidth_or_size <- function (x ) {
1126
+ UseMethod(" linewidth_or_size" )
1127
+ }
1128
+
1129
+ # ' @export
1130
+ linewidth_or_size.Geom <- function (x ) {
1131
+ if (" linewidth" %in% x $ aesthetics()) " linewidth" else " size"
1132
+ }
1133
+
1134
+ # ' @export
1135
+ linewidth_or_size.element <- function (x ) {
1136
+ if (" linewidth" %in% names(x )) " linewidth" else " size"
1137
+ }
1138
+
1139
+
1115
1140
# Convert R pch point codes to plotly "symbol" codes.
1116
1141
pch2symbol <- function (x ) {
1117
1142
lookup <- list (
0 commit comments