Base Plot
p=ggplot(data=xy)+geom_point(aes(x=x,y=y,color=type))
p
# color does not work, use colour instead
p+opts(legend.background=theme_rect(colour="purple",fill="pink",size=3,linetype="dashed"))
p+opts(legend.key=theme_rect(colour='purple',fill='pink',size=0.5,linetype='dashed'))
# to use unit, you need to load package grid, i.e. library(grid)
p+opts(legend.key.size=unit(2,'cm'))
legend.key.width (unit)
p+opts(legend.key.width=unit(5,'cm'))
p+opts(legend.text = theme_text(colour = 'red', angle = 45, size = 10, hjust = 3, vjust = 3, face = 'bold'))
change legend labels
# breaks=c('A','B'), 'A' and 'B' are the default legend in xy
p+scale_colour_hue(name="my legend", breaks=c('A','B'), labels=c('AAA','BBB'))
p+opts(legend.title = theme_text(colour = 'red', angle = 45, size = 10, hjust = 3, vjust = 7, face = 'italic'))
# get rid of legend
p+opts(legend.position='none')
# move legend to the left
p+opts(legend.position='left')
#
define relative coordinates on plot c(x, y) between 0 and 1
p+opts(legend.position=c(0.5,0.5))
legend.justification (?)
#
Justification defines which side of the legend that the legend.position coordinates refer to
#
can use left, right, centre or numeric value (0 ≤ x ≤ 1)
本文介绍如何使用ggplot2包定制图例样式,包括背景、键值、文本、位置等属性调整方法,并演示了如何改变图例标签及标题。
![[转载]ggplot2--Legend(图例操作) [转载]ggplot2--Legend(图例操作)](https://i-blog.csdnimg.cn/blog_migrate/22f7b99e0cdb0f4c1b9ab3fd63b2f0f3.jpeg)
![[转载]ggplot2--Legend(图例操作) [转载]ggplot2--Legend(图例操作)](https://i-blog.csdnimg.cn/blog_migrate/a196c8095c3c3b82440a970851fb782a.jpeg)
![[转载]ggplot2--Legend(图例操作) [转载]ggplot2--Legend(图例操作)](https://i-blog.csdnimg.cn/blog_migrate/e72cce109bccbf84be4cff23077df2a5.jpeg)
![[转载]ggplot2--Legend(图例操作) [转载]ggplot2--Legend(图例操作)](https://i-blog.csdnimg.cn/blog_migrate/cb15ca2dec1352c27ca53f9e8cf67115.jpeg)
![[转载]ggplot2--Legend(图例操作) [转载]ggplot2--Legend(图例操作)](https://i-blog.csdnimg.cn/blog_migrate/fbe658238ba60ea31fd43904a34fcb79.jpeg)
![[转载]ggplot2--Legend(图例操作) [转载]ggplot2--Legend(图例操作)](https://i-blog.csdnimg.cn/blog_migrate/66901d12e68eecf7fff85e0eef8a5baf.jpeg)
![[转载]ggplot2--Legend(图例操作) [转载]ggplot2--Legend(图例操作)](https://i-blog.csdnimg.cn/blog_migrate/2843368b1792718392300e4a1df0d64f.jpeg)
![[转载]ggplot2--Legend(图例操作) [转载]ggplot2--Legend(图例操作)](https://i-blog.csdnimg.cn/blog_migrate/86836cfafaebe9a8d62a4c330b7377f4.jpeg)
![[转载]ggplot2--Legend(图例操作) [转载]ggplot2--Legend(图例操作)](https://i-blog.csdnimg.cn/blog_migrate/3cb6c2ea7b151a2f1491b06eb6b6db54.jpeg)
![[转载]ggplot2--Legend(图例操作) [转载]ggplot2--Legend(图例操作)](https://i-blog.csdnimg.cn/blog_migrate/274d086a231d3c209f817b731c4f79b8.jpeg)
![[转载]ggplot2--Legend(图例操作) [转载]ggplot2--Legend(图例操作)](https://i-blog.csdnimg.cn/blog_migrate/e9aeb4005ec756901775e48f043e24db.jpeg)
![[转载]ggplot2--Legend(图例操作) [转载]ggplot2--Legend(图例操作)](https://i-blog.csdnimg.cn/blog_migrate/da988cc2d6d031311899386e55448d4b.jpeg)
443

被折叠的 条评论
为什么被折叠?



