Trying to create a pie chart that shows the count of films in the IMDB top 250 by their rating / certificate. Despite creating a vector that specifies the manual order I want them, cannot get plotly to change the sorted order of the labels.
How can I manually change the labels for this chart?
x <- c('G', 'PG', 'PG-13', 'R', 'Not Rated', 'Other')
Ratings_df <- df %>%
dplyr::group_by(certificate) %>%
dplyr::summarize(count = n()) %>%
dplyr::mutate(certificate = ifelse(count < 17, "Other", certificate)) %>%
dplyr::group_by(certificate) %>%
dplyr::summarise(count = sum(count)) %>%
dplyr::mutate(certificate = factor(certificate, levels = x)) %>%
dplyr::arrange(certificate) %>%
data.frame()
Ratings_df
plot_ly(Ratings_df, labels = ~certificate, values = ~count) %>%
add_pie(hole=0.6) %>%
layout(xaxis = list(categoryorder = "array",
categoryarray = c('G', 'PG', 'PG-13', 'R', 'Not Rated', 'Other')),
title="Count of Films by Rating")