Question: geom_bar plot with several variables

2

jordi.planells •

**80**wrote:Hi all, I need your help. I am struggling on getting a bar plot with ggplot2 package.

Imagine I have 3 different variables (which would be my y values in aes) that I want to plot for each of my samples (x aes):

```
str(df)
'data.frame': 4 obs. of 4 variables:
$ samples: Factor w/ 4 levels "S1","S2","S3",..: 1 2 3 4
$ v1 : int 234 189 167 235
$ v2 : int 345 265 235 254
$ v3 : int 54 48 32 645
```

I would like to have a barplot in which I have a group per sample (4), each of them with 3 bars, one for each variable (12 bars in total). I know that if I want to extract the height from the df I have to call for stat = "identity". So far this has been my guess, but it's not working properly:

```
n <- ggplot(df) +
geom_bar(mapping = aes(x = samples, y = v1), stat = "identity", position = "dodge") +
geom_bar(mapping = aes(x = samples, y = v2), stat = "identity", position = "dodge") +
geom_bar(mapping = aes(x = samples, y = v3), stat = "identity", position = "dodge")
```

Could you please help me?

Thanks before hand

ADD COMMENT
• link
•
modified 7 weeks ago
by
gpushpaganesan •

**0**• written 6 months ago by jordi.planells •**80**
4 observation of 4 variables: I have Type position in more variable (20),how to give minimum variable(5)

0Excuse me...?

46k