Reputation: 4180
I am trying to use echarts4r
, an R interface to the popular Javascript Echarts library, to build a bar plot within the polar coordinate system.
The help files available indicate that this is simply not possible. In R, there is no coordinate-related argument in e_bar()
(unlike e_line()
, which does have one). Echarts documentation also states that "Polar coordinate can be used in scatter and line chart.".
And yet, here is an example in the Echarts gallery of exactly that plot: https://ecomfe.github.io/echarts-examples/public/editor.html?c=bar-polar-real-estate.
My attempt, obviously unsuccessful, was this:
gen_int <- function(n, k = 10) {
sample(as.integer(1:n), size = k, replace = TRUE)
}
library(dplyr)
dat <- tibble(id = letters[1:10],
x = gen_int(10),
y = gen_int(10))
library(echarts4r)
dat %>%
slice(1:5) %>%
e_charts(id) %>%
e_polar() %>%
e_bar(x, coordinateSystem = list('polar'))
Any ideas how to do this? In ggplot2
, it would look like this:
dat %>%
ggplot(aes(x = id, y = x)) +
geom_col() +
coord_polar()
Thanks for any tips!
Upvotes: 0
Views: 685
Reputation: 2261
Interesting. We can accomplish that by slightly modifying the example in e_polar
.
df <- data.frame(x = 1:10, y = seq(1, 20, by = 2))
df %>%
e_charts(x) %>%
e_polar() %>%
e_angle_axis() %>%
e_radius_axis() %>%
e_bar(y, coordinateSystem = "polar")
As you can see in the example you link there is need for polar, radius and angle axis.
Upvotes: 1