jsl*_*che 29 position r legend ggplot2
我想将我的情节传奇放在情节内,在第一个方面的情节内.
这是一些示例代码:
df=data.frame(
x=runif(10),
y=runif(10),
facet=rep(c("a","b"),5),
color=rep(c("red","blue"),5))
ggplot(data=df,aes(x=x,y=y,color=color))+
geom_point()+
facet_wrap(~facet,ncol=1)
Run Code Online (Sandbox Code Playgroud)
这是结果图:

这里大概是我希望它看起来如何:

感谢您的任何帮助,您可以提供!
Ric*_*ton 25
假设你的情节被保存为 p
p + opts(
legend.position = c(0.9, 0.6), # c(0,0) bottom left, c(1,1) top-right.
legend.background = theme_rect(fill = "white", colour = NA)
)
Run Code Online (Sandbox Code Playgroud)
如果您希望图例背景部分透明,请更改fill为,例如,"#ffffffaa".
Nov*_*ova 14
或者,建立@Richie Cotton的答案,因为opg现在在ggplot2中被弃用(仍假设你的情节被定义为p)
p + theme(legend.position = c(0.9, 0.6)
,legend.background = element_rect(fill = "white", colour = NA))
Run Code Online (Sandbox Code Playgroud)