私はカテゴリ別縦断的データを扱っています。R - ggplot2並列カテゴリプロット
id variable value
1 1 1 c
2 1 2 b
3 1 3 c
4 1 4 c
5 1 5 c
...
variable
は基本的に
時間で
、そしてvalue
は1 id
が取ることができる3つの可能なカテゴリです:私のデータは、以下のような3つの単純な変数を持っています。
は、私は右のそれを得るために少し苦労していますggplot2
でこれに似た「パラレル」縦グラフを、生産に興味を持っています。私は今のところまで来たことはこれです:このグラフで
dt0 %>% ggplot(aes(variable, value, group = id, colour = id)) +
geom_line(colour="grey70") +
geom_point(aes(colour=value, size = nn), size=4) +
scale_colour_brewer(palette="Set1") + theme_minimal()
問題私たちは本当に「遷移」(id
ライン)の「厚さ」を見ることができないということです。
あなたは私を助けることができる場合、私は疑問に思っ:
a)をid
行を可視に役立つ、または他の
Bにフォーム1つの状態を行くid
の数に応じて、それは「厚い」作ります)この状態のid
の番号に応じてre-size
のポイントも欲しいです。私はgeom_point(aes(colour=value, size = nn), size=4)
でそれをやろうとしましたが、うまくいかないようです。
ありがとうございました。
# data #
library(dplyr)
library(ggplot2)
set.seed(10)
# generate random sequences #
dt = as.data.frame(cbind(id = 1:1000, replicate(5, sample(c('a', 'b', 'c'), prob = c(0.1,0.2,0.7), 1000, replace = T))))
# transform to PP file #
dt = dt %>% melt(id.vars = c('id'))
# create a vector 1-0 if the activity was performed #
dt0 = dt %>% group_by(id) %>% mutate(variable = 1:n()) %>% arrange(id)
# create the number of people in that state #
dt0 = dt0 %>% count(id, variable, value)
dt0 = dt0 %>% group_by(variable, value, n) %>% mutate(nn = n())
# to produce the first graph #
library(vcrpart)
otsplot(dt0$variable, factor(dt0$value), dt0$id)
ありがとう – giacomo