在第一个方面的情节位置传奇 [英] Position legend in first plot of facet

查看:184
本文介绍了在第一个方面的情节位置传奇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



下面是一些示例代码:

  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)



下面是结果图:



以下是我想要的样子:





感谢您提供任何帮助! 解决方案

假设您的情节保存为<$ c $ (

$ b

  p + opts(
legend.position = c(0.9, 0.6),#c(0,0)左下角,c(1,1)右上角。
legend.backgro und = theme_rect(fill =white,color = NA)

如果你希望图例背景部分透明,将 fill 更改为例如#ffffffaa


I would like to put my plot legend inside the plot, inside the first plot of a facet.

Here is some example code:

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)

Here is the resulting plot:

And here is roughly how I would like it to look:

Thanks for any help you can provide!

解决方案

Assuming your plot is saved as 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)
)

If you want the legend background partially transparent, change the fill to, e.g., "#ffffffaa".

这篇关于在第一个方面的情节位置传奇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆