Skip to content

Commit 2581b0e

Browse files
committed
multiply by -1 for reversed aes
1 parent 96f998c commit 2581b0e

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

R/ggplotly.R

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ gg2list <- function(p){
100100

101101
## Extract data from built ggplots
102102
built <- ggplot_build2(p)
103-
104103
# Get global x-range now because we need some of its info in layer2traces
105104
ggranges <- built$panel$ranges
106105
# Extract x.range
@@ -161,7 +160,9 @@ gg2list <- function(p){
161160
names(ranks) <- br
162161
misc$breaks[[sc$aesthetics]] <- ranks
163162
}
163+
misc$trans[sc$aesthetics] <- sc$trans$name
164164
}
165+
reverse.aes <- names(misc$trans)[misc$trans=="reverse"]
165166

166167
## get gglayout now because we need some of its info in layer2traces
167168
gglayout <- built$panel$layout
@@ -175,8 +176,16 @@ gg2list <- function(p){
175176
df <- df[order(df$order),]
176177
df$order <- NULL
177178

178-
misc$prestats.data <- merge(built$prestats.data[[i]],
179-
gglayout[, c("PANEL", "plotly.row", "COL")])
179+
prestats <- built$prestats.data[[i]]
180+
## scale_reverse multiples x/y data by -1, so here we undo that so
181+
## that the actual data can be uploaded to plotly.
182+
replace.aes <- intersect(names(prestats), reverse.aes)
183+
for(a in replace.aes){
184+
prestats[[a]] <- -1 * prestats[[a]]
185+
}
186+
misc$prestats.data <-
187+
merge(prestats,
188+
gglayout[, c("PANEL", "plotly.row", "COL")])
180189

181190
# Add global x-range info
182191
misc$prestats.data$globxmin <- ggxmin

R/trace_generation.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ layer2traces <- function(l, d, misc) {
4141

4242
## For non-numeric data on the axes, we should take the values from
4343
## the original data.
44-
for (axis.name in c("x", "y")) {
45-
if (!misc$is.continuous[[axis.name]]) {
44+
for (axis.name in c("x", "y")) {
45+
if(!misc$is.continuous[[axis.name]]) {
4646
aes.names <- paste0(axis.name, c("", "end", "min", "max"))
4747
aes.used <- aes.names[aes.names %in% names(g$aes)]
4848
for(a in aes.used) {

0 commit comments

Comments
 (0)