3

The context

I know the following code produces the following plot

library('echarts4r')

dat  <- structure(list(
  labels = c("string4",
             "string3",
             "string2",
             "string1"),
  quantity = c(19L,
               10L,
               15L,
               20L)),
  row.names = 4:1,
  class = "data.frame")

dat <- dat[order(dat$labels, decreasing = TRUE),]

dat |>
  e_charts(y  = labels, reorder = FALSE) |>
  e_parallel(labels, quantity, opts = list(smooth = TRUE))

enter image description here

The question

I want these labels (the ones pointed by the blue arrows) to be shown on the left instead of on the right of the vertical line. How can I move them to the left side?

enter image description here

What I've tried

I've taken a look at the documentation, as suggested by @socialscientist in its answer, and I've tried the following to no avail.

The following doesn't throw an error, but doesn't move the labels.

df <- data.frame(
  labels = c("string4", "string3", "string2", "string1"),
  column2 = c(19L, 10L, 15L, 20L))
df |>
  e_charts(y = labels) |>
  e_labels(position = 'left') |>
  e_parallel(labels, column2)

The following throws an error.

df <- data.frame(
  labels = c("string4", "string3", "string2", "string1"),
  column2 = c(19L, 10L, 15L, 20L))
df |>
  e_charts(y = labels) |>
  e_parallel(labels, column2) |>
  e_labels(position = 'left')

The folowing doesn't throw an error, but doesn't move the labels.

df <- data.frame(
  labels = c("string4", "string3", "string2", "string1"),
  column2 = c(19L, 10L, 15L, 20L))
df |>
  e_charts(y = labels) |>
  e_labels(offset = c(123, 123)) |>
  e_parallel(labels, column2)

The following doesn't throw an error, but doesn't move the labels.

df <- data.frame(
  labels = c("string4", "string3", "string2", "string1"),
  column2 = c(19L, 10L, 15L, 20L))
df |>
  e_charts(y = labels) |>
  e_labels(position = 'insideRight', distance = 123) |>
  e_parallel(labels, column2)
rdrg109
  • 265
  • 1
  • 8
  • Currently looks like this is not implemented in `echarts4r`. My suggestions are that you either (a) pass your chart to `echarts4rOutput()` and try to manually figure out how to change the way `parallelAxis` works since the Y axis you see is NOT the actual chart's Y-axis, (b) swap to `MASS` or `ggplot2` to create your parallel coordinates plot https://r-graph-gallery.com/93-parrallel-plot (which can be made interactive with e.g. shiny or whatever), or (c) write up your own solution with D3.js https://bl.ocks.org/jasondavies/1341281. – socialscientist Jul 28 '22 at 04:29

1 Answers1

0

I couldn't find an effectively method to feed the necessary input into e_parallel. However, You can change it as an after thought.

I used this function to flip the defaults for axisTick.length and axisLabel.margin and axisLabel.align for the parallelAxis (left side only).

fixLabs <- function(plt) {
  plt$x$opts$parallelAxis[[1]]$axisTick <- list(length = -5) # default is +5
  plt$x$opts$parallelAxis[[1]]$axisLabel <- list(margin = -8, # default is +8
                                                 align = "right")
  plt
}

This is how you use it.

dat |>
  e_charts(y  = labels, reorder = FALSE) |>
  e_parallel(labels, quantity, 
             opts = list(smooth = TRUE))  %>% 
  fixLabs()

enter image description here

Kat
  • 15,669
  • 3
  • 18
  • 51