如何在e_mark_point中返回不同的min、avg和max值?

bqjvbblv  于 7个月前  发布在  其他
关注(0)|答案(1)|浏览(46)

我有这个数据:

library(echarts4r)

x <- c(10, 20, 30, 45, 46, 50)
y <- c(12, 25, 36, 46, 49, 59)

matrixinc1 <- data.frame(x, y)

near_line <- function(matriz) {
  diferenca <- abs(matriz[, 1] - matriz[, 2])
  indice <- which.min(diferenca)
  return(matriz[indice, , drop = FALSE])
}

near <- near_line(matrixinc1)
near

matrixinc1 |>
  e_charts(x) |>
  e_line(x) |>
  e_line(y) |>
  e_mark_point(data = near)

字符串
我尝试将x值用45表示,y值用46表示。但我无法在图表中进行此调整。是否可以这样做,使标记不相互重叠?
我也试过这个:

matrixinc1 |>
  e_charts(x) |>
  e_line(x) |>
  e_line(y) |>
  e_mark_point("x", data = near[,1]) |> 
  e_mark_point("y", data = near[,2])


还有这个:

matrixinc1[["test"]] <- near$x

avg <- list(
  type = "value",
  value = near$x,  # Atribui o valor de near[,1] à propriedade 'value'
  name = "AVG"
)

matrixinc1 |>
  e_charts(x) |>
  e_line(x) |>
  e_line(y) |>
  e_mark_point("x", data = avg)

qoefvg9y

qoefvg9y1#

从你的问题来看,我们并不清楚你想实现什么。如果你想在特定的点上放置标记,你可以通过设置coord属性来实现,该属性应该是一个包含x和y坐标的向量。为此,我重构了你的函数以返回所需的向量。

library(echarts4r)

x <- c(10, 20, 30, 45, 46, 50)
y <- c(12, 25, 36, 46, 49, 59)

matrixinc1 <- data.frame(x, y)

near_line <- function(matriz, cols = c("x", "y")) {
  diferenca <- abs(matriz[, 1] - matriz[, 2])
  indice <- which.min(diferenca)

  unname(
    unlist(
      matriz[indice, cols, drop = TRUE]
    )
  )
}

near_y <- list(
  coord = near_line(matrixinc1),
  value = "y"
)

near_x <- list(
  coord = near_line(matrixinc1, c("x", "x")),
  value = "x"
)

matrixinc1 |>
  e_charts(x) |>
  e_line(x) |>
  e_line(y) |>
  e_mark_point(serie = "y", data = near_y) |>
  e_mark_point(
    serie = "x", data = near_x, symbolRotate = 180,
    label = list(verticalAlign = "top")
  )

字符串


的数据

相关问题