Rgeek
Rgeek

Reputation: 449

Plotting values from multiple columns but for one row

I have data for a single row and multiple columns.I would like to plot the data for each column in a single plot.I have 100 columns like this.What would be the best way to do this in R.

matplot(df[1,],type="o")

I have tried various options such as above for the below data:

  gene  Sample_23770_A54T_RNAX  Sample_27931_RNAX   Sample_28891_RNAX   Sample_28897_RNAX Sample_28977_RNAX Sample_28979_RNAX   Sample_PM100_Z1_1_RNA   Sample_PM117_Z10_1_Case_RNASeq Sample_PM117_Z1_1_Case_RNASeq
  CD274 5.9315  1.9569  10.3786 5.2705  5.7112  1.814   0.3493  0.6846  1.0373

Also,Can I use ggplot function for multiple columns?Basically,I want to plot the expression value for the single row comparing between 100 different columns .

Upvotes: 2

Views: 4288

Answers (1)

blakeoft
blakeoft

Reputation: 2400

With ggplot2:

library(ggplot2)
cd274 <- read.table(text = "gene  Sample_23770_A54T_RNAX  Sample_27931_RNAX   Sample_28891_RNAX   Sample_28897_RNAX Sample_28977_RNAX Sample_28979_RNAX   Sample_PM100_Z1_1_RNA   Sample_PM117_Z10_1_Case_RNASeq Sample_PM117_Z1_1_Case_RNASeq
CD274 5.9315  1.9569  10.3786 5.2705  5.7112  1.814   0.3493  0.6846  1.0373", header = T)
cd274 <- melt(cd274[, 2:ncol(cd274)])
ggplot(cd274, aes(x = variable, y = value)) + geom_bar(stat = "identity") + coord_flip()

Upvotes: 2

Related Questions