Hello everyone,
I'm new in the R and shiny world and I cannot solve my problem at the moment.
So I have this example dataset and I want to have in shiny a stacked barchart which is grouped_by(Geschlecht). But I want to in one bar the Gebiete, the Geschlecht but split in female(1213), male(1214) and both together (1212). Can anyone help me?
I tried the following code but it does not work at all:
data_select <- mydata %>% select(KZID, JAHR_VON, WERT, GEBID)
data_select <- data_select %>%
rename(Geschlecht = KZID
,Jahre = JAHR_VON
,Bevölkerung = WERT
,Gebiete =GEBID)
data_select
First I did the rest in plotly but then I read it is not possible to group and stack in plotly.
#Grouped Bar Chart
df_sa_group <- data_select%>%group_by(Geschlecht, Gebiete)
plot_ly(data=df_sa_group, x= ~Jahre, y= ~Bevölkerung, name = "Bevölkerung pro Jahr", type= "bar")%>%
add_trace(y=~Geschlecht, name="Geschlecht")%>% layout(yaxis=list(title='Anzahl'), barmode ='group')