2
votes

I am having some trouble displaying the size legend in my plot and changing the name of my size legend.

My data is corp already has a size column which is either of the values 5, 10, 20

I am using ggplot2 I already have a legend for the color

  1. I want to add one for the size and manually change the size labels..

  2. How do I increase the the font of the legend ? It's super tiny (FIN, IND UTIL) also the 15 for the size shouldnt be there i want to just omit it and display both legends side by side.

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
I'm guessing you'd get a lot further with data other people could actually run. Please provide a minimally working example(MWE)Tyler Rinker
you are right. ill post some data with it tommqfd

1 Answers

1
votes

Although I can't use your data yet, you can try adding the following code:

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