Skip to content

Commit 618456d

Browse files
committed
only use trace.order.list for axes with type=category
1 parent df927ee commit 618456d

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

R/ggplotly.R

+17-13
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,28 @@ gg2list <- function(p){
305305
ax.list$tickangle <- -tick.text$angle
306306
}
307307
ax.list$tickfont <- theme2font(tick.text)
308+
309+
## determine axis type first, since this information is used later
310+
## (trace.order.list is only used for type=category).
311+
title.text <- e(s("axis.title.%s"))
312+
ax.list$titlefont <- theme2font(title.text)
313+
ax.list$type <- if(misc$is.continuous[[xy]]){
314+
"linear"
315+
}else if(misc$is.discrete[[xy]]){
316+
"category"
317+
}else if(misc$is.date[[xy]] || misc$is.datetime[[xy]]){
318+
"date"
319+
}else{
320+
stop("unrecognized data type for ", xy, " axis")
321+
}
308322

309323
# Translate axes labels.
310324
scale.i <- which(p$scales$find(xy))
311325
ax.list$title <- if(length(scale.i)){
312326
sc <- p$scales$scales[[scale.i]]
313-
trace.order.list[[xy]] <- sc$limits
327+
if(ax.list$type == "category"){
328+
trace.order.list[[xy]] <- sc$limits
329+
}
314330
trace.name.map[sc$breaks] <- sc$labels
315331
if (is.null(sc$breaks)) {
316332
ax.list$showticklabels <- FALSE
@@ -346,18 +362,6 @@ gg2list <- function(p){
346362
p$labels[[xy]]
347363
}
348364

349-
title.text <- e(s("axis.title.%s"))
350-
ax.list$titlefont <- theme2font(title.text)
351-
ax.list$type <- if(misc$is.continuous[[xy]]){
352-
"linear"
353-
}else if(misc$is.discrete[[xy]]){
354-
"category"
355-
}else if(misc$is.date[[xy]] || misc$is.datetime[[xy]]){
356-
"date"
357-
}else{
358-
stop("unrecognized data type for ", xy, " axis")
359-
}
360-
361365
ax.list$zeroline <- FALSE # ggplot2 plots do not show zero lines
362366
# Lines drawn around the plot border.
363367
ax.list$showline <- !is.blank("panel.border", TRUE)

0 commit comments

Comments
 (0)