[R] ggplot2 legend,axis

坐标轴

参考

http://blog.csdn.net/bone_ace/article/details/47427453#标签修改

命令

scale_x_continue(breaks=c(1:20),labels=c(1:20),limits=c(1,20) ##limits设置区间大小,breaks设置刻度位置,labels设置刻度

图例

参考

https://github.com/tidyverse/ggplot2/wiki/Legend-Attributes
http://blog.csdn.net/bone_ace/article/details/47284805

命令
生成数据需要aes:geom_point(aes(shape=factor(d$kind),color=factor(d$kind)),size=3)
修改text:

如果是通过fill分组,scale_fill_discrete(labels=c('interaction effect','main effect'))
如果是颜色,scale_color_discrete(labels=c('interaction effect','main effect'))
如果还有形状,还需要添加scale_shape_discrete(labels=c('interaction effect','main effect'))
以此类推

修改位置、大小、border、标题:


theme(
##no legend.title
legend.title = element_blank(),
## legend border
legend.box.background = element_rect( size = 1),
##legend inside, change relative positions by 0.95, 0.95
legend.position = c(.95, .95),
legend.justification = c("right", "top"),
legend.box.just = "right",
legend.margin = margin(6, 6, 6, 6),
##legend text setting
legend.text = element_text(size = 15)
)

你可能感兴趣的:([R] ggplot2 legend,axis)