Hello folks, I am really new and just about to lear how to use r for my thesis for data visualization.
I have the following Problem:
I've got an Excel Chart with a column with three Patient Groups 1,2 and 3 --> 1 = 17x, 2= 15x, 3= 60x
I want to generate a bar chart showing the three groups with different colors.
This is the code:
Patientengruppe <- factor(Gesamt$Patientengruppe)
ggplot(Gesamt, aes(x=Patientengruppe, color = Patientengruppe, fill= Patientengruppe))+
geom_bar(fill = "steelblue")+
labs(x="Patientengruppe", y = "ANzahl der Patienten")+
ggtitle("Aufteilung der Patienten in Patientengruppen")
Now I've got the problem, that I can't change the colors of the single bars. All if them are steel blue. I figured, that there is probably a problem with the group Patientengruppe/ aes but I don't know how to extract the groups from the column to work on the bars separately and add them into one chart.
I don't think so
Thats the strucure of my table:
Group
Pat1 1
Pat2 2
Pat3 3
Pat4 2
Pat 5 1
Pat 6 3
My x lab is the group --> 1,2,3
And the y lab has to be the number of patients --> 17,15,60
I think, that my struggle is that x is not dependent on y all the examples are like date connected with temperature or time with speed but I just want to show my groups with the number of patient for each group.
Looking at your code, I noticed that you have defined fill option twice, where the fill = "steelblue" in the geom_bar is placed on top of the fill= Patientengruppe..
So, you should only assign the fill = Patientengruppe in the ggplot(aes(..)) or in the geom_bar(aes(..))
To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:
ggplot(Gesamt, aes(x=Patientengruppe, color = Patientengruppe, fill= Patientengruppe))+
geom_bar()+
labs(x="Patientengruppe", y = "ANzahl der Patienten")+
ggtitle("Aufteilung der Patienten in Patientengruppen")