@@ -297,11 +297,35 @@ justify_grobs <- function(grobs, x = NULL, y = NULL, hjust = 0.5, vjust = 0.5,
297
297
# '
298
298
# ' @noRd
299
299
rotate_just <- function (angle , hjust , vjust ) {
300
- # convert angle to radians
301
- rad <- (angle %|| % 0 ) * pi / 180
302
-
303
- hnew <- cos(rad ) * hjust - sin(rad ) * vjust + (1 - cos(rad ) + sin(rad )) / 2
304
- vnew <- sin(rad ) * hjust + cos(rad ) * vjust + (1 - cos(rad ) - sin(rad )) / 2
300
+ # # Ideally we would like to do something like the following commented-out lines,
301
+ # # but it currently yields unexpected results for angles other than 0, 90, 180, 270.
302
+ # # Problems arise in particular in cases where the horizontal and the vertical
303
+ # # alignment model differ, for example, where horizontal alignment is relative to a
304
+ # # point but vertical alignment is relative to an interval. This case arises for
305
+ # # x and y axis tick labels.
306
+ # #
307
+ # # For more details, see: https://github.com/tidyverse/ggplot2/issues/2653
308
+
309
+ # # convert angle to radians
310
+ # rad <- (angle %||% 0) * pi / 180
311
+ #
312
+ # hnew <- cos(rad) * hjust - sin(rad) * vjust + (1 - cos(rad) + sin(rad)) / 2
313
+ # vnew <- sin(rad) * hjust + cos(rad) * vjust + (1 - cos(rad) - sin(rad)) / 2
314
+
315
+ angle <- (angle %|| % 0 ) %% 360
316
+ if (0 < = angle & angle < 90 ) {
317
+ hnew <- hjust
318
+ vnew <- vjust
319
+ } else if (90 < = angle & angle < 180 ) {
320
+ hnew <- 1 - vjust
321
+ vnew <- hjust
322
+ } else if (180 < = angle & angle < 270 ) {
323
+ hnew <- 1 - hjust
324
+ vnew <- 1 - vjust
325
+ } else if (270 < = angle & angle < 360 ) {
326
+ hnew <- vjust
327
+ vnew <- 1 - hjust
328
+ }
305
329
306
330
list (hjust = hnew , vjust = vnew )
307
331
}
0 commit comments