Position legend in first plot of facet

后端 未结 2 548
野性不改
野性不改 2020-12-25 11:28

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=runi         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-25 11:58

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

提交回复
热议问题