Skip to content

Commit

Permalink
Merge pull request #233 from mcol/issue_220
Browse files Browse the repository at this point in the history
Make interactive mode in plot_AbanicoPlot() functional again
  • Loading branch information
RLumSK authored Sep 11, 2024
2 parents e00a5f2 + ffbecda commit bbb7856
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
2 changes: 2 additions & 0 deletions NEWS.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ which would generate unexpected warnings (#163, @mcol).
### `plot_AbanicoPlot()`
* Argument `plot.ratio` will now throw an error on non-positive numerical
values (#221, fixed in #222).
* The function doesn't crash anymore when setting `interactive = TRUE` (#220,
fixed in #233).

### `plot_DetPlot()`
* Argument `signal.integral.max` is now enforced to be greater than
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<!-- NEWS.md was auto-generated by NEWS.Rmd. Please DO NOT edit by hand!-->

# Changes in version 0.9.25.9000-59 (2024-09-10)
# Changes in version 0.9.25.9000-59 (2024-09-11)

**This package version requires R \>= 4.3**

Expand Down Expand Up @@ -99,6 +99,8 @@

- Argument `plot.ratio` will now throw an error on non-positive
numerical values (#221, fixed in \#222).
- The function doesn’t crash anymore when setting `interactive = TRUE`
(#220, fixed in \#233).

### `plot_DetPlot()`

Expand Down
48 changes: 23 additions & 25 deletions R/plot_AbanicoPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -3587,29 +3587,30 @@ plot_AbanicoPlot <- function(
x <- NA
y <- NA


## tidy data ----
data <- plot.output
kde <- data.frame(x = data$KDE[[1]][ ,2], y = data$KDE[[1]][ ,1])

# radial scatter plot ----
point.text <- paste0("Measured value:</br>",
data$data.global$De, " &plusmn; ", data$data.global$error,"</br>",
point.text <- paste0("Measured value:<br />",
data$data.global$De, " &plusmn; ",
data$data.global$error, "<br />",
"P(",format(data$data.global$precision, digits = 2, nsmall = 1),", ",
format(data$data.global$std.estimate, digits = 2, nsmall = 1),")")

IAP <- plotly::plot_ly(data = data$data.global, x = precision, y = std.estimate,
IAP <- plotly::plot_ly(data = data$data.global,
x = data$data.global$precision,
y = data$data.global$std.estimate,
type = "scatter", mode = "markers",
hoverinfo = "text", text = point.text,
name = "Points",
yaxis = "y")

ellipse <- as.data.frame(ellipse)
IAP <- plotly::add_trace(IAP, data = ellipse,
x = ellipse.x, y = ellipse.y,
hoverinfo = "none",
name = "z-axis (left)",
x = ~ellipse.x, y = ~ellipse.y,
type = "scatter", mode = "lines",
hoverinfo = "none", text = "",
name = "z-axis (left)",
line = list(color = "black",
width = 1),
yaxis = "y")
Expand All @@ -3618,10 +3619,10 @@ plot_AbanicoPlot <- function(
ellipse.right$ellipse.x <- ellipse.right$ellipse.x * 1/0.75

IAP <- plotly::add_trace(IAP, data = ellipse.right,
x = ellipse.x, y = ellipse.y,
hoverinfo = "none",
name = "z-axis (right)",
x = ~ellipse.x, y = ~ellipse.y,
type = "scatter", mode = "lines",
hoverinfo = "none", text = "",
name = "z-axis (right)",
line = list(color = "black",
width = 1),
yaxis = "y")
Expand All @@ -3640,9 +3641,9 @@ plot_AbanicoPlot <- function(
for (i in 1:length(major.ticks.y)) {
major.tick <- data.frame(x = major.ticks.x, y = rep(major.ticks.y[i], 2))
IAP <- plotly::add_trace(IAP, data = major.tick,
x = x, y = y, showlegend = FALSE,
hoverinfo = "none",
x = ~x, y = ~y, showlegend = FALSE,
type = "scatter", mode = "lines",
hoverinfo = "none", text = "",
line = list(color = "black",
width = 1),
yaxis = "y")
Expand All @@ -3652,24 +3653,23 @@ plot_AbanicoPlot <- function(
for (i in 1:length(minor.ticks.y)) {
minor.tick <- data.frame(x = minor.ticks.x, y = rep(minor.ticks.y[i], 2))
IAP <- plotly::add_trace(IAP, data = minor.tick,
hoverinfo = "none",
x = x, y = y, showlegend = FALSE,
x = ~x, y = ~y, showlegend = FALSE,
type = "scatter", mode = "lines",
hoverinfo = "none", text = "",
line = list(color = "black",
width = 1),
yaxis = "y")
}


# z-tick label
tick.text <- paste(" ", exp(tick.values.major))
tick.pos <- data.frame(x = major.ticks.x[2],
y = major.ticks.y)

IAP <- plotly::add_trace(IAP, data = tick.pos,
x = x, y = y, showlegend = FALSE,
text = tick.text, textposition = "right",
x = ~x, y = ~y, showlegend = FALSE,
hoverinfo = "none",
text = tick.text, textposition = "right",
type = "scatter", mode = "text",
yaxis = "y")

Expand All @@ -3679,7 +3679,7 @@ plot_AbanicoPlot <- function(
format(exp(z.central.global), digits = 2, nsmall = 1))

IAP <- plotly::add_trace(IAP, data = central.line,
x = x, y = y, name = "Central line",
x = ~x, y = ~y, name = "Central line",
type = "scatter", mode = "lines",
hoverinfo = "text", text = central.line.text,
yaxis = "y",
Expand All @@ -3692,17 +3692,16 @@ plot_AbanicoPlot <- function(
KDE.y <- (KDE[[1]][ ,1] - z.central.global) * min(ellipse[,1])
KDE.curve <- data.frame(x = KDE.x, y = KDE.y)
KDE.curve <- KDE.curve[KDE.curve$x != xy.0[1], ]

KDE.text <- paste0("Value:",
format(exp(KDE[[1]][ ,1]), digits = 2, nsmall = 1), "</br>",
format(exp(KDE.curve$x), digits = 2, nsmall = 1), "<br />",
"Density:",
format(KDE[[1]][ ,2], digits = 2, nsmall = 1))
format(KDE.curve$y, digits = 2, nsmall = 1))

IAP <- plotly::add_trace(IAP, data = KDE.curve,
x = ~x, y = ~y, name = "KDE",
type = "scatter", mode = "lines",
hoverinfo = "text",
text = KDE.text,
x = x, y = y, name = "KDE",
type = "scatter", mode = "lines",
line = list(color = "red"),
yaxis = "y")

Expand All @@ -3727,7 +3726,6 @@ plot_AbanicoPlot <- function(
xref = "x", yref = "y",
fillcolor = "grey",
opacity = 0.2))

)

# show and return interactive plot ----
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test_plot_AbanicoPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ test_that("Test examples from the example page", {
expect_type(plot_AbanicoPlot(data = ExampleData.DeValues,
pch = NA,
output = TRUE), "list")

## interactive mode
expect_silent(plot_AbanicoPlot(ExampleData.DeValues, interactive = TRUE))
})

test_that("more coverage", {
Expand Down

0 comments on commit bbb7856

Please sign in to comment.