2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

両方向の棒グラフを簡単に描く

Posted at

背景

複数の異なる条件で,upregulateされた遺伝子数とdownregulateされた遺伝子数を1つのグラフに棒グラフとして描きたいと考えました.
最初はピラミッドプロットを使おうと考えましたが,barplotでできたのでメモします.

データの用意

df <- data.frame(up=c(1,3,5), down=c(2,5,7))
d1 <- matrix(1:6 ,3, 2)
d2 <- matrix(6:1 ,3, 2)
result
> df
  up down
1  1    2
2  3    5
3  5    7
> d1
     [,1] [,2]
[1,]    1    4
[2,]    2    5
[3,]    3    6
> d2
     [,1] [,2]
[1,]    6    3
[2,]    5    2
[3,]    4    1

プロット

barplotadd=Tというオプションが肝です.
あとはylimで調整しています.

barplot( df$up, ylim=c( -1*max(df$down), max(df$up) ) ,
         main="test", ylab="down                 up")
barplot( -1 * df$down, add=T )

barplot_1.png

またbeside=Tを使うこともできます.

barplot( d1, beside=T, main="test", ylab="down             up",
         names.arg=c("A","B"), ylim=c( -1 * max(d2), max(d1)) )
barplot( -1 * d2, beside=T, add=T )

barplot_2.png

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?