我正在尝试构建一个显示从一个类到另一个类的转换的图.我想让圆圈代表根据类属性调整大小的每个类,以及从一个类到另一个类的箭头,根据从一个类到另一个类的过渡数来确定大小.
举个例子:
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") +
scale_size_continuous(range=c(4,20)) +
geom_segment( data=trans, aes( x=x.from, y=y.from, xend=x.to, yend=y.to, size=amount ),lineend="round",arrow=arrow(),alpha=0.5)
Run Code Online (Sandbox Code Playgroud)

我希望能够以不同的比例将箭头缩放到圆圈.理想情况下,我想要一个带有两个刻度的图例,但我知道这可能是不可能的(在一个ggplot上使用两个刻度颜色渐变)
有没有比将任意缩放应用于底层数据更优雅的方法呢?
I'm trying to build a network plot in ggplot. Two things: 1) I need to put the nodes at specific (x, y) values. This isn't a problem. 2) The network plot is directed but I need to be able to show differences in going from, say, Node B to Node A than from Node A to Node B.
It's that latter bit I'm having trouble with. Basically I need to offset two lines running parallel between nodes. Ultimately the lines' …