简体   繁体   中英

R plotly - How to make labels and legend larger in donut chart?

I'm making a donut chart with the following code

data <- data.frame(
  category=c("Successful", "Unsuccessful", "Pending"),
  amount=c(45, 26, 23)
)

# Make the plot
df <- data
fig <- df %>% plot_ly(labels = ~category, values = ~amount, marker = list(colors = c('#00aa7f', '#ff0000','#ccccc7')))
fig <- fig %>% add_pie(hole = 0.55) 
fig

This results in a nice donut chart - but I feel like the legend and label are too small. 在此处输入图像描述

When I edit my code with the following: Nothing happens

df <- data
fig <- df %>% plot_ly(labels = ~category, values = ~amount, marker = list(colors = c('#00aa7f', '#ff0000','#ccccc7', size = 10)))
fig <- fig %>% add_pie(hole = 0.55) 
fig

When I try this code - the font is way to big and although I try to adjust it - the size doesn't decrease.

# Make the plot
df <- data
fig <- df %>% plot_ly(labels = ~category, values = ~amount, marker = list(colors = c('#00aa7f', '#ff0000','#ccccc7')), size = 10)
fig <- fig %>% add_pie(hole = 0.55) 
fig

在此处输入图像描述

What am I doing wrong?

The label size can the changed by textfont argument inside the add_pie function. The legend size and hovertext size can be adjusted inside the layout function with the arguments hoverlabel and legend .

fig <- df %>% plot_ly(labels = ~category,
                      values = ~amount, 
                      marker = list(colors = c('#00aa7f', '#ff0000','#ccccc7')))
fig <- fig %>% 
  add_pie(hole = 0.55,
          textfont = list(size = 18))  %>%
  layout(legend = list(font = list(size = 18)),
         hoverlabel = list(font = list(size = 18)))
fig

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM