-2

I'm a very beginner in R and not familiar with the syntax. Your help would be very much appreciated.

I have a Data frame with 3 columns and 27 rows.

Gene_Name Cell_line1 Cell_line2
gene1        23          45
gene2        0.6         21
gene3        34          18
---
gene27       45          23

I want to make Grouped Barplot where I have gene names on the X axis and cell_line1 and Cell_line2 values on the Y in different colors.

I was trying to make it with ggplot2

 p<- ggplot(data=df, aes(Gene_Names, Cell_line1)) + geom_bar(stat="identity", position = "dodge")+ theme(axis.text.x = element_text(angle = 90, hjust = 1))

Can you correct my code? or suggest something else?

Thanks.

R_biology
  • 1
  • 3

1 Answers1

0

Here's example data, since you didn't provide much to work with:

df <- data.frame(Gene_Names = LETTERS, 
                 Cell_line1 = 10, 
                 Cell_line2 = 8)

Here's how you reshape the data:

df <- df %>% tidyr::gather("Cell_line", "Value", 2:3) 

Example of a plot as you described:

ggplot(data=df, aes(x = Gene_Names, y = Value, fill = Cell_line)) + 
  geom_bar(stat="identity", position = "dodge", width = .5)+ 
  theme(axis.text.x = element_text(angle = 90, hjust = 1))
ssp3nc3r
  • 3,662
  • 2
  • 13
  • 23