2013-12-07 35 views
2

我正在使用'符号'制作气泡图,并且我希望绘图区以外的图例显示气泡大小的索引(类似于ggplot会产生什么)。我想坚持使用符号并避免ggplot。使用'符号'命令为气泡图创建图例

我的数据:

V1<-c(1,10,30,22,22,20) 
V2<-c(4,17,4,33,33.2,15) 
V3<-c(20,20,15,34,33,30) 
V4<-c("A","A","A","B","B","B") 
DF<-data.frame(V1,V2,V3,V4) 

我没有情节的传奇人物:

symbols(DF$V1,DF$V2,circles=V3,inches=0.35,fg="darkblue",bg="red") 
text(DF$V1,DF$V2+c(0, 0, 0, 1, -1,0),V4,cex=0.5) 

这里是使用ggplot一个例子。我希望创建一个类似于此图中的图例,并将其与上述符号代码一起使用。

library(ggplot2)  
ggplot(DF,aes(x=V1,y=V2,size=V3,label=V4),legend=FALSE) + 
    geom_point(color='darkblue', 
       fill="red", shape=21) + 
    theme_bw() + 
    geom_text(size=5) 

回答

1

类似:

symbols(DF$V1,DF$V2, circles = V3, inches = 0.35, fg = "darkblue", bg = "red") 
text(DF$V1, DF$V2 + c(0, 0, 0, 1, -1,0), V4, cex = 0.5) 

legend(
    "topright", 
    legend=c("15", "20", "25", "30"), 
    pch = 21, 
    bty = "n", 
    col = "black", 
    pt.bg = "red",   
    pt.cex = c(0.5,1,1.5,2) 
    )  

# thanks to at @Josh O'Brien for pt.cex