Search code examples
recharts4r

How to rotate the axis labels on echarts4r radar chart?


Reproducible example:

library(echarts4r)

# Sample data
data <- data.frame(
  Category = c("A", "B", "C", "D", "E"),
  Value = c(80, 50, 60, 70, 40)
)

# Creating a radar chart
e_charts(data, Category) |> 
  e_radar(Value)

I tried following with no rotation in the labels A, B, ..., E:

e_charts(data, Category) |> 
  e_radar(Value) |> 
  e_radar_opts(
    axisLabel = list(
      rotate = 45
    )
  )

Solution

  • You need to set the nameRotate property of the indicator object.

    enter image description here

    library(echarts4r)
    
    # Sample data
    data <- data.frame(
      Category = c("A", "B", "C", "D", "E"),
      Value = c(80, 50, 60, 70, 40)
    )
    
    # Creating a radar chart
    e_charts(data, Category) |> 
      e_radar(Value) |> 
      e_radar_opts(
        axisName = list(
          color = "blue",
          formatter = JS("function (value, indicator) {
                            indicator.nameRotate = 45;
                            return value;
                          }")
        )
      )