ggplot主题设置

2020-03-23  本文已影响0人  yingyonghui

theme(
### 图title字号、加粗、居中
plot.title =element_text(size=18,face="bold",hjust=0.5)

### 坐标轴
#坐标轴刻度字体
axis.text= element_text(size=16,colour= 'black'),
#x轴标签旋转90度,并做垂直和水平方向的位置微调
axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)
#坐标轴标度
axis.ticks.x=element_blank(),
#坐标轴线条
axis.line.x=element_blank()
#坐标轴倾斜45度后对齐
axis.text.x=element_text(angle=45,hjust=1,vjust=1),
#坐标轴title
axis.title= element_text(size = 16),
#坐标轴的粗细和颜色
axis.line = element_line(size= 0.5,colour = 'black'),

### 坐标轴标签内容修改
scale_x_continuous(breaks=1:5, labels =c('T0','T1','T3','T7','T14')) 

### 画布背景
#白色画布背景,黑色边框,若不设置color则无边框
panel.background=element_rect(fill="white",color="black")
#画布网格为空
panel.grid = element_blank()
#画布网格为灰色,粗细为1,虚线
panel.grid = element_line(colour='gray',size=1,linetype =3)
#主网格与次网格
panel.grid.minor=element_line(size=1,linetype =3,color="purple"),
panel.grid.major=element_line(size=2,linetype =3,color="grey70"),
#画布四周方框(待求证)
panel.border = element_blank(),

### 图注
#legend title
legend.title=element_blank(),
#legend 字体
legend.text = element_text( size = 14),
#legend位置
legend.position='right',
#去掉图注所用的标志的灰色背景
legend.key = element_blank()
)
#图注分成两列
guides(color=guide_legend('Celltype',override.aes=list(size=3),ncol=2))

### 渐变色
#设置图注中渐变颜色的显示和范围
scale_color_gradient(low="red",high ="green",limits=c(0,1))
#设置图注中3个渐变颜色的显示和范围
scale_colour_gradient2(low="red",mid='lightgreen',high ="purple",midpoint=0.125,limits=c(0,0.25))
#设置图注中n个渐变颜色的显示和范围
scale_colour_gradientn(colours=c("red",'lightgreen','lightblue','purple'),limits=c(0,0.05))

### 柱形图分组,调整注释条上字体字号颜色角度
facet_grid(~manufacturer) + theme(strip.text.x = element_text(size = 8, colour = "red", angle = 90))

### 坐标轴
#x,y轴范围与刻度显示
scale_x_continuous(limits=c(-50,40),breaks=c(-40,-20,0,20,40))
scale_y_continuous(limits=c(-50,40),breaks=c(-40,-20,0,20,40))

### 添加垂直线段
geom_vline(xintercept=0,size=0.3,linetype=2,colour='grey')
geom_hline(yintercept=0,size=0.3,linetype=2,colour='grey')

### 将同一组的散点圈起来(待验证)
stat_ellipse(aes(x=tSNE_1,y=tSNE_2,fill=cellname),
               geom="polygon", level=0.95, alpha=0.2)

### ggplot 默认渐变色系
mycolors <- scales::hue_pal(c=100)(25)
scales::show_col(mycolors)

###RColorBrewer对比色系
library(RColorBrewer)
mycolors <- c(brewer.pal(name="Dark2", n = 8), brewer.pal(name="Accent", n = 7), brewer.pal(name="Set1", n = 9), brewer.pal(name="Set3", n = 12), brewer.pal(name="Set2", n = 8), brewer.pal(name="Paired", n = 10),brewer.pal(name="Pastel1", n = 9),brewer.pal(name="Pastel2", n = 7))
mycolors <- unique(mycolors)

###产生RGB颜色
 mycolor=rgb(248, 203, 173, max=255)

###紫色到黄色渐变
viridis::viridis_pal()(100)
colorRampPalette(c("#440154" ,"#21908C", "#FDE725"))(100)
上一篇 下一篇

猜你喜欢

热点阅读