为什么 plot_ly 饼图在 R 中总是将第 5 值文本从白色变为黑色?
Why does plot_ly pie chart always turn 5th value text from white to black in R?
我正在使用 R 中的 plotly 包制作饼图,每当我有 5 个可视化选择时,它总是将第 5 个更改为 brown/black 颜色,尽管我将颜色覆盖为白色的。如果它与 NA 的值有关,我该如何解决?我有标记为 NA 的数据,因此我需要保留它的名称。为了它的价值,我尝试重命名为“NA”,但它仍然显示相同。
为什么会发生这种情况,我该如何解决?
library(plotly)
library(dplyr)
data <- tibble(employee = c("Justin", "Corey","Sibley", "Justin", "Corey","Sibley", "Lisa", "NA"),
education = c("graudate", "student", "student", "graudate", "student", "student", "nurse", "doctor"),
fte_max_capacity = c(1, 2, 3, 1, 2, 3, 4, 5),
project = c("big", "medium", "small", "medium", "small", "small", "medium", "medium"),
aug_2021 = c(1, 1, 1, 1, 1, 1, 2, 5),
sep_2021 = c(1, 1, 1, 1, 1, 1, 2, 5),
oct_2021 = c(1, 1, 1, 1, 1, 1, 2, 5),
nov_2021 = c(1, 1, 1, 1, 1, 1, 2, 5))
data2 <- data %>%
dplyr::group_by(employee) %>%
mutate(sum = sum(rowSums(select(cur_data_all(), contains("_20"))))) %>%
dplyr::select(employee, sum) %>%
distinct()
my_colors <- c("#CA001B", "#1D28B0", "#D71DA4", "#00A3AD", "#FF8200", "#753BBD", "#00B5E2", "#008578", "#EB6FBD", "#FE5000", "#6CC24A", "#D9D9D6", "#AD0C27", "#950078")
fig <- plot_ly(type='pie', labels=data2$employee, values=data2$sum,
textinfo='label+percent', marker = list(colors = my_colors),
insidetextorientation='horizontal')
fig
t <- list(
family = "Arial",
size = 18,
color = 'white')
fig %>% layout(font=t, showlegend = FALSE)
在insidetextfont
-
中设置颜色
library(plotly)
fig <- plot_ly(type='pie', labels=data2$employee, values=data2$sum,
textinfo='label+percent', insidetextfont = list(color = '#FFFFFF'),
marker = list(colors = my_colors),
insidetextorientation='horizontal')
fig
我正在使用 R 中的 plotly 包制作饼图,每当我有 5 个可视化选择时,它总是将第 5 个更改为 brown/black 颜色,尽管我将颜色覆盖为白色的。如果它与 NA 的值有关,我该如何解决?我有标记为 NA 的数据,因此我需要保留它的名称。为了它的价值,我尝试重命名为“NA”,但它仍然显示相同。
为什么会发生这种情况,我该如何解决?
library(plotly)
library(dplyr)
data <- tibble(employee = c("Justin", "Corey","Sibley", "Justin", "Corey","Sibley", "Lisa", "NA"),
education = c("graudate", "student", "student", "graudate", "student", "student", "nurse", "doctor"),
fte_max_capacity = c(1, 2, 3, 1, 2, 3, 4, 5),
project = c("big", "medium", "small", "medium", "small", "small", "medium", "medium"),
aug_2021 = c(1, 1, 1, 1, 1, 1, 2, 5),
sep_2021 = c(1, 1, 1, 1, 1, 1, 2, 5),
oct_2021 = c(1, 1, 1, 1, 1, 1, 2, 5),
nov_2021 = c(1, 1, 1, 1, 1, 1, 2, 5))
data2 <- data %>%
dplyr::group_by(employee) %>%
mutate(sum = sum(rowSums(select(cur_data_all(), contains("_20"))))) %>%
dplyr::select(employee, sum) %>%
distinct()
my_colors <- c("#CA001B", "#1D28B0", "#D71DA4", "#00A3AD", "#FF8200", "#753BBD", "#00B5E2", "#008578", "#EB6FBD", "#FE5000", "#6CC24A", "#D9D9D6", "#AD0C27", "#950078")
fig <- plot_ly(type='pie', labels=data2$employee, values=data2$sum,
textinfo='label+percent', marker = list(colors = my_colors),
insidetextorientation='horizontal')
fig
t <- list(
family = "Arial",
size = 18,
color = 'white')
fig %>% layout(font=t, showlegend = FALSE)
在insidetextfont
-
library(plotly)
fig <- plot_ly(type='pie', labels=data2$employee, values=data2$sum,
textinfo='label+percent', insidetextfont = list(color = '#FFFFFF'),
marker = list(colors = my_colors),
insidetextorientation='horizontal')
fig