Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you center the title in a R Plotly pie chart?

Tags:

r

plotly

I am working with Plotly using R and am having trouble centering the title over the pie chart. The title looks like it is a little off to the right. Is there a way to do this and move it left or closer to the middle of the pie chart?

This is the code:

label_names = c('Feeds','All Others') 
numbers = c(first_reported, not_first_reported)

pie_colors <- c('rgba(173,216,230,1)', 'rgba(0,0,139,1)')
plot_ly(labels=label_names, values=numbers, type='pie', 
        insidetextfont = list(color = '#FFFFFF'),
        marker = list(colors=pie_colors)) %>%
  layout(title = 'Portion of Feeds')

What the chart looks like:

enter image description here

like image 246
sectechguy Avatar asked Oct 21 '25 17:10

sectechguy


1 Answers

Looks similar to this question, Left-align chart title in plotly, just slightly modifying the answer here, should work for this too.

plot_ly(labels=label_names, values=numbers, type='pie', 
        insidetextfont = list(color = '#FFFFFF'),
        marker = list(colors=pie_colors)) %>%
  add_annotations(
    y=1.05, 
    x=0.5, 
    text="Portion of Feeds", 
    showarrow=F,
    font=list(size=15)
  )

source:

like image 195
radhikesh93 Avatar answered Oct 23 '25 06:10

radhikesh93



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!