Fabrice
Fabrice

Reputation: 387

HighcharteR : How to add new labels inside slice of pie chart

I want to add new labels on each slice of a pie chart using HighcharteR (Highchart for R).

When a slice is selected, it is highlighted but not the others. I want that each label in slice react the same way too.

I found some post using javascript solution but not with HighcharteR.

Thanx for the clue

enter image description here

Upvotes: 1

Views: 783

Answers (1)

Kat
Kat

Reputation: 18744

You need to assign a negative distance to the data labels to move the labels inside a pie chart. I suggest that you use % to keep things relative.

Here's an example.

library(highcharter)

df1 <- data.frame(a = c("Piece 1", "Piece 2", "Piece 3"),
                  b = c(10, 20, 40))

highchart() %>% 
  hc_add_series(df1, type = "pie", 
                dataLabels = list(distance = '-30%', # <- this puts labels inside
                                  backgroundColor = "white"),
                hcaes(x = a, y = b))

enter image description here

Upvotes: 1

Related Questions