簡體   English   中英

如何在ggplot2中獲取和修改尺寸圖例

[英]how to get and modify size legend in ggplot2

我在繪圖中顯示尺寸圖例並更改尺寸圖例的名稱時遇到了一些麻煩。

我的公司數據已經有一個size列,該列是值5、10、20之一

我正在使用ggplot2,我已經有了顏色的圖例

  1. 我想為尺寸添加一個,然后手動更改尺寸標簽。

  2. 如何增加圖例的字體? 它非常小(FIN,IND UTIL),尺寸15也不應存在,我只想忽略它,並同時顯示兩個圖例。

在此處輸入圖片說明

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)

盡管我還無法使用您的數據,但是您可以嘗試添加以下代碼:

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"))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM