Let's say I have a dataset with percentages of males and females in each town, and groups of towns (let's say states):
town <- 1:4
females <- c(64.5, 86.3, 35.7, 45.6)
males <- 100 - females
state <- c(1, 2, 2, 1)
df <- c(town, females, males, state)
What I wanna do is generate a stacked horizontal bar chart using the Plotly package, in a way that I'll have 2 bars (one for each state) and the mean percentages of each gender in these bars. The sum of mean males and females should be 100%. I'm aware I'll have to transform the data I have, maybe use a group_by state, but I don't know exactly how.
Thanks in advance!