如何在ggplot2中获取和修改大小图例

时间:2014-02-06 01:45:21

标签: r ggplot2

我在绘图中显示尺寸图例并更改尺寸图例的名称时遇到了一些问题。

我的数据是corp已经有一个大小列,其值为5,10,20

我正在使用ggplot2我已经有了颜色的图例

  1. 我想为大小添加一个并手动更改尺寸标签..

  2. 如何增加图例的字体?它非常小(FIN,IND UTIL) 还有15个大小不应该在那里我想省略它并且并排显示两个传说。

  3. enter image description here

    p <- ggplot(corp, aes(x=annRisk, y=annRet,  color = corp$subsector1, face = "bold"))
    
    p<- p + geom_point(aes(size = corp$Colsize), alpha = 0.55)
    
    p<-p + scale_size(range = c(8, 20))
    
    p<-p + scale_colour_manual("", values = c("UTIL" = "#fdcc8b", "IND" = "#fc8d59", "FIN" = "#d7301f",
    "ABS" = "#74a9cf", "CMBS" = "#0570b0", "LA" = "#8c96c6", "SOV"= "#88419d", "SUPRA" = "#b3cde3"))
    
    p<-p+labs(title = "SOME TITLE")
    
    print(p)
    
    p<-p+theme(plot.title = element_text(face = "bold", size = 20))
    
    p<-p+theme(axis.title.x = element_text(size = 20), axis.text.x = element_text(size = 13))
    p<-p+theme(axis.title.y = element_text(size = 20), axis.text.y = element_text(size = 13))
    
    p<-p+geom_text(aes(label=ifelse(Colsize>=10,subsector2,"")), size=5,color = "black", face = "bold", hjust=-0.1, vjust = 0.1)
    
    
    p<-p+scale_x_continuous(labels = percent, name = "Annualized Risk", limits = c(0.05, 0.09))
    
    p<-p+scale_y_continuous(labels = percent, name = "Annualized Return", limits = c(0.04, 0.08))
    
    p<-p+ theme(legend.position = "bottom")
    print(p)
    

1 个答案:

答案 0 :(得分:1)

虽然我还无法使用您的数据,但您可以尝试添加以下代码:

p <- p + theme(legend.position = "bottom",
               legend.title = element_blank(),
               legend.text = element_text(size=14),
               legend.box = "horizontal")

p <- p + scale_size_manual(values=c(5,10,20), labels = c("5","10","20"))