Skip to content

Commit

Permalink
Use raw series for y-axis ticks when log = TRUE
Browse files Browse the repository at this point in the history
This creates y-axis labels using the raw series values, instead of the
log series values. So the labels and locations are in round values of
the raw series, but rendered at the logged locations.

See #103.
  • Loading branch information
joshuaulrich committed Oct 9, 2023
1 parent 0e4d3ed commit 28d6ad3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -1233,8 +1233,18 @@ new.replot_xts <- function(panel=1,asp=1,xlim=c(1,10),ylim=list(structure(c(1,10
}

# y-axis grid line labels and locations
grid_loc <- pretty(yl, Env$yaxis.ticks)
grid_loc <- grid_loc[grid_loc >= yl[1] & grid_loc <= yl[2]]
if (use_log_yaxis) {
# labels are based on the raw series values
ylim_series <- exp(yl)
grid_lbl <- pretty(ylim_series, Env$yaxis.ticks)
grid_lbl <- grid_lbl[grid_lbl >= ylim_series[1] & grid_lbl <= ylim_series[2]]
# locations are based on the log series values
grid_loc <- log(grid_lbl)
} else {
grid_loc <- pretty(yl, Env$yaxis.ticks)
grid_loc <- grid_loc[grid_loc >= yl[1] & grid_loc <= yl[2]]
grid_lbl <- grid_loc
}

# draw y-axis grid lines
segments(x0 = xlim[1], y0 = grid_loc,
Expand All @@ -1247,7 +1257,7 @@ new.replot_xts <- function(panel=1,asp=1,xlim=c(1,10),ylim=list(structure(c(1,10
if (draw_left_yaxis) {
text(x = xlim[1],
y = grid_loc,
labels = format(grid_loc, justify = "right"),
labels = format(grid_lbl, justify = "right"),
col = theme$labels,
srt = theme$srt,
offset = 0.5,
Expand All @@ -1260,7 +1270,7 @@ new.replot_xts <- function(panel=1,asp=1,xlim=c(1,10),ylim=list(structure(c(1,10
if (draw_right_yaxis) {
text(x = xlim[2],
y = grid_loc,
labels = format(grid_loc, justify = "right"),
labels = format(grid_lbl, justify = "right"),
col = theme$labels,
srt = theme$srt,
offset = 0.5,
Expand Down

0 comments on commit 28d6ad3

Please sign in to comment.