Reputation: 43
Encountered a challenge while attempting to utilize e_text_g()
in echarts4r to place text on both the left and right sides of a plot. While applying e_text_g()
individually for left and right sides works seamlessly, combining both commands in a chain results in failure. A reproducible example is provided below:
library(echarts4r)
df <- data.frame(
x = seq(10),
y = rnorm(10, 10, 3)
)
Text placement on the left side works as expected:
df |>
e_charts(x) |>
e_scatter(y) |>
echarts4r::e_text_g(
style = list(text = "left",
fontSize = 30,
fill = "red"),
left = "10%",
top = "7%"
)
Similarly, on the right side:
df |>
e_charts(x) |>
e_scatter(y) |>
echarts4r::e_text_g(
style = list(text = "right",
fontSize = 30,
fill = "red"),
right = "10%",
top = "7%"
)
However, when trying to place text on both sides by chaining both commands, this does not work:
df |>
e_charts(x) |>
e_scatter(y) |>
e_text_g(
style = list(text = "right",
fontSize = 30,
fill = "red"),
right = "10%",
top = "7%") |>
e_text_g(
style = list(text = "left",
fontSize = 30,
fill = "red"),
left = "10%",
top = "7%"
)
I would expect to successfully place text on both the left and right sides of the plot by chaining the e_text_g commands.
Any alternative approaches or suggestions for achieving the placement of text on both sides of the plot with reproducible distances from the borders are greatly appreciated.
Upvotes: 0
Views: 81
Reputation: 43
This is a bit of a hack, but this works as expected:
df |>
e_charts(x) |>
e_scatter(y) |>
echarts4r::e_title(
text = "right",
textStyle = list(
fontSize = 30,
color = "red",
fontWeight = 'normal'
),
right = "10%",
top = "7%"
) |>
echarts4r::e_text_g(
style = list(
text = "left",
fontSize = 30,
fill = "red"
),
left = "10%",
top = "7%"
)
df |>
e_charts(x) |>
e_scatter(y) |>
echarts4r::e_title(
text = "right",
textStyle = list(
fontSize = 30,
color = "red",
fontWeight = 'normal'
),
right = "10%",
top = "7%"
) |>
echarts4r::e_title(
text = "left",
textStyle = list(
fontSize = 30,
color = "red",
fontWeight = 'normal'
),
left = "10%",
top = "7%"
)
Upvotes: 1