GGR绘图:围绕图例的线条

GGR绘图:围绕图例的线条,r,plot,ggplot2,legend,R,Plot,Ggplot2,Legend,我正在尝试使用ggplot2进行数据打印 纯粹出于表面原因,我希望在我的图例周围画一条线,以便更好地将其与情节区分开来(即,图例框周围的黑色轮廓)。我在任何论坛上都找不到这个问题的答案,但也许你有什么建议 library(ggplot2) Res = matrix(ncol = 3, nrow = 500) Res[,1] = 1:500 Res[,2] = sin((2*pi)/100*Res[,1]) Res[,3] = cos((2*pi)/100*Res[,1]) Res = as.d

我正在尝试使用ggplot2进行数据打印

纯粹出于表面原因,我希望在我的图例周围画一条线,以便更好地将其与情节区分开来(即,图例框周围的黑色轮廓)。我在任何论坛上都找不到这个问题的答案,但也许你有什么建议

library(ggplot2)

Res = matrix(ncol = 3, nrow = 500)
Res[,1] = 1:500
Res[,2] = sin((2*pi)/100*Res[,1])
Res[,3] = cos((2*pi)/100*Res[,1])
Res = as.data.frame(Res)
colnames(Res) = c("X", "Y1", "Y2")

ggplot(Res, aes(X)) + 
  geom_line(aes(y = Y1, colour = "1"), size = 2) +
  geom_line(aes(y = Y2, colour = "2"), size = 2) +
  scale_color_discrete(name = "Y's", labels = c(" sine", " cosine")) +
  theme(legend.position=c(0.9, 0.7))

这将给出一个关于图例的概要

library(ggplot2)

Res = matrix(ncol = 3, nrow = 500)
Res[,1] = 1:500
Res[,2] = sin((2*pi)/100*Res[,1])
Res[,3] = cos((2*pi)/100*Res[,1])
Res = as.data.frame(Res)
colnames(Res) = c("X", "Y1", "Y2")

ggplot(Res, aes(X)) + 
  geom_line(aes(y = Y1, colour = "1"), size = 2) +
  geom_line(aes(y = Y2, colour = "2"), size = 2) +
  scale_color_discrete(name = "Y's", labels = c(" sine", " cosine")) +
  theme(legend.position=c(0.9, 0.7)) +  
  theme(legend.background = element_rect(colour = 'black', fill = 'white', linetype='solid'))

您可以在此处阅读有关图例设置的更多信息

这将提供有关图例的概述

library(ggplot2)

Res = matrix(ncol = 3, nrow = 500)
Res[,1] = 1:500
Res[,2] = sin((2*pi)/100*Res[,1])
Res[,3] = cos((2*pi)/100*Res[,1])
Res = as.data.frame(Res)
colnames(Res) = c("X", "Y1", "Y2")

ggplot(Res, aes(X)) + 
  geom_line(aes(y = Y1, colour = "1"), size = 2) +
  geom_line(aes(y = Y2, colour = "2"), size = 2) +
  scale_color_discrete(name = "Y's", labels = c(" sine", " cosine")) +
  theme(legend.position=c(0.9, 0.7)) +  
  theme(legend.background = element_rect(colour = 'black', fill = 'white', linetype='solid'))

您可以在此处阅读有关图例设置的更多信息。

图例方形框,一个边框?在
主题(…)中添加
legend.background=element_rect(fill=“grey”,color=“black”)
应该通过在legendI周围添加黑色边框来区分图例。我更多地考虑了图例框周围的轮廓,边框?在
主题(…)
中添加
legend.background=element_rect(fill=“grey”,color=“black”)
应该通过在legendI周围添加黑色边框来区分图例。我更想在图例框周围添加一个轮廓。完美!非常感谢你!完美的非常感谢你!