[英]ggplot2 legend not showing up
有人可以幫我弄清楚如何在與紅點相關的右下角放置一個圖例嗎? 我只需要名稱“我的投資組合”和一個紅色指示器。 我不知道為什么一開始就沒有傳說
library(ggplot2)
x <- c(1,2,3)
y <- c(4,5,6)
ggplot(as.data.frame(cbind(x,y)), aes(x, y)) +
geom_line() +
geom_point(aes(2.5,5.5, colour = "red"),
shape = 18,
size = 3) +
ggtitle("Efficient Frontier") +
xlab("Volatility (Weekly)") +
ylab("Expected Returns (Weekly)") +
theme(plot.title = element_text(size=14, face="bold.italic", hjust = 0.5, margin=margin(0,0,15,0)),
axis.title.x = element_text(size = 10, margin=margin(15,0,0,0)),
axis.title.y = element_text(size = 10, margin=margin(0,15,0,0)),
panel.border = element_rect(colour = "black", fill=NA, size=1),
legend.position = "bottomright")
謝謝
使用legend.justification
:
library(tidyverse)
ggplot(as.data.frame(cbind(x,y)), aes(x, y)) +
geom_line() +
geom_point(aes(2.5,5.5, colour = "red"),
shape = 18,
size = 3) +
ggtitle("Efficient Frontier") +
xlab("Volatility (Weekly)") +
ylab("Expected Returns (Weekly)") +
theme(plot.title = element_text(size=14, face="bold.italic", hjust = 0.5, margin=margin(0,0,15,0)),
axis.title.x = element_text(size = 10, margin=margin(15,0,0,0)),
axis.title.y = element_text(size = 10, margin=margin(0,15,0,0)),
panel.border = element_rect(colour = "black", fill=NA, size=1),
legend.position = "bottom",
legend.justification = "right")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.