(注-これは、ggplotで複数のサイズのスケールを使用するのと同じ作業ですが、別の質問をしています)
あるクラスから別のクラスへの遷移を示すプロットを作成しようとしています。各クラスを表す円と、あるクラスから別のクラスへの遷移を表す矢印が必要です。
矢印を描画するために、geom_segmentとarrow()を使用しています。次の方法はありますか?
- 矢印が円に到達する前に停止させます
- 両方向に矢印がある場合、それらが重なるのではなく「回避」されるように位置を調整します。
ここで役立つことをするためにposition="dodge"を取得できませんでした。
例として:
library(ggplot2)
points <- data.frame( x=runif(10), y=runif(10),class=1:10, size=runif(10,min=1000,max=100000) )
trans <- data.frame( from=rep(1:10,times=10), to=rep(1:10,each=10), amount=runif(100)^3 )
trans <- merge( trans, points, by.x="from", by.y="class" )
trans <- merge( trans, points, by.x="to", by.y="class", suffixes=c(".to",".from") )
ggplot( points, aes( x=x, y=y ) ) + geom_point(aes(size=size),color="red",shape=1) +
scale_size_continuous(range=c(4,20)) +
geom_segment( data=trans[trans$amount>0.6,], aes( x=x.from, y=y.from, xend=x.to, yend=y.to ),lineend="round",arrow=arrow(),alpha=0.5, size=0.3)