本文共 1489 字,大约阅读时间需要 4 分钟。
xy <- data.frame(x=1:10, y=10:1, type = rep(LETTERS[1:2], each=5)) p=ggplot(data=xy)+geom_point(aes(x=x,y=y,color=type))
# 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'))
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'))
# 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'))
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 p+ opts(legend.justification = 'right', legend.position=c(0.25,0.3)) #
can use left, right, centre or numeric value (0 ≤ x ≤ 1) Reference
转载地址:http://sjixi.baihongyu.com/