A similar question has been asked but left unanswered. I need a pie a nested pie chart that has the outer values as a subset of the inner values.
For example I have a simple data table of CD's I have purchased in the past year, I want the pie chart to show the number of CD's from each continent the band is from and the outer ring so show the individual countries of each band from the particular continent.
The hover data for the inside pie chart is correct but the data for the outer ring is misleading. For instance, Germany has 15 CD's out of the 40 European CD's yet Germany's percentage claims 8.62%. The German % is true against the total 100% but against the 40 European CD's purchased this year, Germany is 37.5%
I cannot figure out how to either change the data frame to provide these numbers or how to get plotly to do it.
This is a sample of my orignal data set:
Artist Album Year Country Continent
1 Myrath Legacy 2016 Tunisia Asia
2 Myrath Sands 2011 Tunisia Asia
3 Orphaned Shalem 2011 Israel Asia
4 Orphaned Unsung 2018 Israel Asia
The pie chart is rendered as:
output$bandChart <- renderPlotly({
plot_ly(freefilter() ,labels = ~Country, values = ~AlbumCount,
showlegend = FALSE
) %>%
add_pie(hole = 0.6,
textinfo = 'label',
textposition = 'inside',
insidetextfont = list(color = '#FFFFFF'),
marker = list(line = list(color = '#FFFFFF', width = 1)),
direction = 'clockwise',
sort = FALSE,
text = ~paste(Country, AlbumCount),
hoverinfo = 'text + percent') %>%
add_pie(freefilter(),labels = ~Continent, values = ~AlbumCount,
textinfo = 'label',
textposition = 'inside',
direction = 'clockwise',
sort = FALSE,
name = "Continent Data,
marker = list(line = list(color = '#FFFFFF', width = 1)),
domain = list(x = c(.2, 0.8), y = c(0.2, .8))
) %>%
config (collaborate = FALSE, displaylogo = FALSE ) %>%
layout(title = "Band Locations",
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
autosize = FALSE)
})
Im using shiny and didn't include those parts of the code.
Thanks
coord_polar()
. – Jannik Buhr