Reputation: 33
In an echarts4r scatter plot, is it possible to add horizontal jitter with a discrete x axis?
library(echarts4r)
library(tidyverse)
df <- tibble(x = c("a", "a", "b", "b", "c", "c"),
y = c(1, 2, 3, 3, 4, 5),
z = c(1, 2, 3, 3, 4, 5))
df |>
e_charts(x) |>
e_scatter(y, symbol_size = 15) |>
e_scatter(z, symbol_size = 15, symbol="diamond", jitter_amount = 1) |>
e_color(
c("red", "blue")
)
The jitter option adds vertical jitter (blue diamonds) instead of the desired horizontal jitter.
Upvotes: 1
Views: 123
Reputation: 41469
You could set x_index = 1
to your e_scatter
and use a second x axis with should not be shown to get the jitter of your points like this:
library(echarts4r)
library(tidyverse)
df <- tibble(x = c("a", "a", "b", "b", "c", "c"),
y = c(1, 2, 3, 3, 4, 5),
z = c(1, 2, 3, 3, 4, 5))
df |>
e_charts(x) |>
e_scatter(y, symbol_size = 15) |>
e_scatter(z, symbol_size = 15, symbol="diamond", jitter_amount = 2, x_index = 1) |>
e_color(
c("red", "blue")
) |>
e_x_axis(index = 1, show=F)
Created on 2023-03-12 with reprex v2.0.2
Upvotes: 0