Help ggplot in shiny stacked and groupby bar chart

Hello everyone,

I'm new in the R and shiny world and I cannot solve my problem at the moment.
grafik

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')

As a beginner to R you may benefit from studying this useful book.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.