也许这是一个愚蠢的问题,但我找不到ggplot2手册中的答案,也没有找到"阿姨"谷歌......
如果我有一个中点和一个直径,如何用ggplot2绘制一个圆作为附加图层?谢谢你的帮助.
我想将散点图上的点的颜色比例渐变与图表上某些文本的颜色比例渐变结合起来.我可以单独执行它们,如下面的示例所示,但我似乎无法将它们放在一起......有没有办法做到这一点?
这是我想要组合的两种类型图(p和p1)的示例代码
l <- data.frame(prev=rnorm(1266),
aft=rnorm(1266),
day=as.factor(wday(sample(c(2:6),1266,replace=TRUE),abbr=TRUE, label=TRUE)),
month=as.factor(month(Sys.Date()+months(sample(0:11,1266,replace=TRUE)),abbr=TRUE, label=TRUE)),
ind=c(1:1266))
cors <- ddply(l, c("month", "day"), summarise, cor = round(cor(prev, aft), 3))
# below the text gains the colour gradient
p <- ggplot(l, aes(x=prev, y=aft)) +
geom_point() +
scale_colour_gradient(low = "red", high="blue")+
facet_grid(day~month, scales="free_x")+
geom_text(data=cors,aes(label=paste("r= ",cor,sep=""), size=abs(cor), colour=cor), x=Inf, y=Inf, vjust=1, hjust=1, show_guide=FALSE)+
geom_hline(aes(yintercept=0))+
geom_smooth(method="loess")
p
# below the points gain the colour gradient
p1 <- ggplot(l, aes(x=prev, y=aft)) +
geom_point(aes(colour=ind)) +
scale_colour_gradient("gray")+
facet_grid(day~month, scales="free_x")+
geom_text(data=cors,aes(label=paste("r= ",cor,sep=""), size=abs(cor), colour=cor), x=Inf, …Run Code Online (Sandbox Code Playgroud) (注意 - 这是与在 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)
Run Code Online (Sandbox Code Playgroud)
