博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ggplot2--Legend(图例操作)
阅读量:4162 次
发布时间:2019-05-26

本文共 1489 字,大约阅读时间需要 4 分钟。

Base Plot

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))
p

legend.background (rect)

# color does not work, use colour instead
p+opts(legend.background=theme_rect(colour="purple",fill="pink",size=3,linetype="dashed"))

legend.key (rect)

p+opts(legend.key=theme_rect(colour='purple',fill='pink',size=0.5,linetype='dashed'))

legend.key.size (unit)

# 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'))

legend.text (text)

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'))

legend.title (text)

p+opts(legend.title = theme_text(colour = 'red', angle = 45, size = 10, hjust = 3, vjust = 7, face = 'italic'))

legend.position (?)

# 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
 
p+ opts(legend.justification = 'right', legend.position=c(0.25,0.3))
can use left, right, centre or numeric value (0 ≤ x ≤ 1)
Reference
1. 

转载地址:http://sjixi.baihongyu.com/

你可能感兴趣的文章
如何防止sql注入
查看>>
springmvc传值
查看>>
在Eclipse中查看Android源码
查看>>
Android使用webservice客户端实例
查看>>
[转]C语言printf
查看>>
C 语言 学习---回调、时间定时更新程序
查看>>
第十一章 - 直接内存
查看>>
Single Number II --出现一次的数(重)
查看>>
对话周鸿袆:从程序员创业谈起
查看>>
Mysql中下划线问题
查看>>
Xcode 11 报错,提示libstdc++.6 缺失,解决方案
查看>>
vue项目打包后无法运行报错空白页面
查看>>
Vue 解决部署到服务器后或者build之后Element UI图标不显示问题(404错误)
查看>>
element-ui全局自定义主题
查看>>
facebook库runtime.js
查看>>
js报错显示subString/subStr is not a function
查看>>
高德地图js API实现鼠标悬浮于点标记时弹出信息窗体显示详情,点击点标记放大地图操作
查看>>
vue项目使用安装sass
查看>>
在osg场景中使用GLSL语言——一个例子
查看>>
laravel 修改api返回默认的异常处理
查看>>