20180808
R
・積み上げグラフ
データを行列にする必要があるので「matrix」を用いる
下記の場合。18行1列となる(らしい)
> PTS = t$PTS
> PTS
[1] 5078 5072 4942 4857 4766 4754 4753 4683 4644 4522 4495 4494
[13] 4418 4416 4370 4328 4276 4253
> dm=matrix(PTS,18,1)
> barplot(dm)
その結果
色付けしたいとき
>barplot(dm,col=c("red", "blue"))
その結果
積み上げグラフを「ggplot2」で行うときの参照URL
https://stats.biopapyrus.jp/r/ggplot/geom_bar.html
・積み上げの上級編
install.packages("ggsci")
library(ggplot2)
library(ggsci)
x <- data.frame(
cell = c("A", "A", "B", "B", "C", "C"),
sample = c("1", "2", "1", "2", "1", "2"),
weight = c(0.3, 0.35, 0.61, 0.52, 0.33, 0.36)
)
g <- ggplot(x, aes(x = cell, y = weight, fill = sample))
g <- g + geom_bar(stat = "identity")
g <- g + scale_fill_nejm()
plot(g)