图的意义:
点的坐标代表其突变频率,越靠近三角形的一个角,代表在这个类型突变越多;
点的大小代表在glioma这个病中,总共的突变频率;
颜色代表相对突变频率
应用场景
展示3种不同疾病或者3组之间某个指标的相关性
代码部分
library(ggtern)
citation(package = 'ggtern')
library(tidyverse)
library(scales)
library(ggplot2)
library(directlabels)
Sys.setenv(LANGUAGE = "en") #显示英文报错信息
options(stringsAsFactors = FALSE) #禁止chr转成factor
df <- read.csv("input.csv")
head(df)
ggtern(data=df, aes(x=df$Frequency.in.pGBM,
y=df$Frequency.in.LGG,
z=df$Frequency.in.sGBM)) +
geom_point(size = df$Alteration.Frequency.in.glioma)
###把size扩大50倍
ggtern(data=df,aes(x=df$Frequency.in.pGBM,y=df$Frequency.in.LGG,z=df$Frequency.in.sGBM)) +
geom_point(size=df$Alteration.Frequency.in.glioma*50)
#用0.1作为阈值来分段,
df$allfrequency <- ifelse(df$Alteration.Frequency.in.glioma >= 0.1,
10^(df$Alteration.Frequency.in.glioma) * 3,
50 * (df$Alteration.Frequency.in.glioma))
ggtern(data=df, aes(x=df$Frequency.in.pGBM,
y=df$Frequency.in.LGG,
z=df$Frequency.in.sGBM)) +
geom_point(size=df$allfrequency)
#作图
p <- ggtern(data=df, aes(x=df$Frequency.in.pGBM, y=df$Frequency.in.LGG, z=df$Frequency.in.sGBM)) +
geom_point(size = df$allfrequency) + #用allfrequency来定义点的大小
theme_custom(18, '') + #字体大小
labs(x='Primary\nGBM', z='Secondary\nGBM', y='Low Grade Glioma')+ #加label
theme(tern.panel.background = element_rect(fill = "white"), #背景白色
tern.panel.grid.minor = element_line(color = "gray90"), #背景网格颜色
tern.axis.arrow.show = TRUE, #画箭头
#箭头颜色和大小 L: LEFT, R: RIGHT, T: TOP
tern.axis.arrow.T = element_line(color ='#0000E3', size = 2.5),
tern.axis.arrow.L = element_line(color = '#FF44FF', size = 2.5),
tern.axis.arrow.R = element_line(color = 'red', size = 2.5),
#箭头上字的颜色
tern.axis.arrow.text.L = element_text(color = 'black'),
tern.axis.arrow.text.T = element_text(color = 'black'),
tern.axis.arrow.text.R = element_text(color = 'black'),
#箭头距离三角形的远近
tern.axis.arrow.sep = 0.1,
#背景网格颜色、线型、粗细
tern.panel.grid.major.T = element_line(color = 'gray92', linetype = 1, size = 0.8),
tern.panel.grid.major.L = element_line(color = 'gray92', linetype = 1, size = 0.8),
tern.panel.grid.major.R = element_line(color = 'gray92', linetype = 1, size = 0.8),
tern.panel.grid.minor.T = element_line(color = 'gray94', linetype = 1, size = 0.8),
tern.panel.grid.minor.L = element_line(color = 'gray94', linetype = 1, size = 0.8),
tern.panel.grid.minor.R = element_line(color = 'gray94', linetype = 1, size = 0.8),
#坐标轴title的字体颜色、大小
tern.axis.title.L = element_text(color = '#FF44FF', size = 11),
tern.axis.title.T = element_text(color = '#0000E3', size = 11),
tern.axis.title.R = element_text(color = 'red', size = 11),
#坐标轴标签的字号
tern.axis.text.L = element_text(size = 17,face = 'bold'),
tern.axis.text.R = element_text(size = 17,face = 'bold'),
tern.axis.text.T = element_text(size = 17,face = 'bold'),
#整体画布往上移动一点,避免压到字
tern.axis.vshift = 0.04,
#坐标轴粗细
tern.axis.line.T = element_line(size = 0.8),
tern.axis.line.R = element_line(size = 0.8),
tern.axis.line.L = element_line(size = 0.8)) +
#画一条虚线
geom_Lisoprop(color='darkgrey', value=.5, linetype=4, size=1)
p
p1 <- p +
#分别画三种亚型的突变频率,图层叠加
geom_point(aes(color=df$Frequency.in.sGBM), size=df$allfrequency, alpha=0.7) + #半透明
geom_point(aes(color=df$Frequency.in.pGBM), size=df$allfrequency, alpha=0.7) +
geom_point(aes(color=df$Frequency.in.LGG), size=df$allfrequency, alpha=0.7) +
scale_color_gradient2(low='red', mid = '#0000E3', high ='purple', midpoint = 0.33, #三种颜色
guide = FALSE) + #不画图例
#每个圈圈外面加个黑圈
geom_point(size=df$allfrequency, shape = 1, alpha = 0.8,
stroke = 0.7, #线的粗细
color = "black")
p1
突变频率越高,则堆砌的颜色则越深,越有意义。
##添加label
p1 + geom_dl(aes(label=Gene), method = "smart.grid")
网友评论