将变量函数标签添加到 R 中的三元图
Add variable function label to ternary plot in R
我想将我的数据绘制成三元图,其中基因在三种条件之一下上升或下降,即。更接近显示更高值的条件。
- 每个变量的值是否独立于值进行标准化?
- 我可以为选定的“基因”变量添加一个标签,该变量表示变量“func2”吗?
这是我获得的(顶部)和我想要的(底部)的可重现示例
gene <- c("Gene1", "Gene2", "Gene3", "Gene4","Gene5", "Gene6")
func1 <- c("A", "B", "C", "D", "C", "A")
func2 <- c("A1", "B1", "C1", "D1", "C2", "A2")
Cond1 <- c(0.007623561, 0.004639893, 0.000994121, 0.017494429, 0.000366445, 0.006663334)
Cond2 <- c(0.011299941, 0.009994388, 0.001012428, 0.013695669, 0.000299771, 0.010287904)
Cond3 <- c(0.005055458, 0.016826251, 0.001311254, 0.016115009, 0.000242897, 0.004583889)
df <- data.frame(gene, func1, func2, Cond1, Cond2, Cond3)
library(ggplot2)
library(ggtern)
ggtern(data=df,aes(x=Cond1,y=Cond2,z=Cond3,color=func1)) +
theme_bw() +
geom_point() +
labs(x="Cond1",y="Cond2",z="Cond3") +
scale_T_continuous(breaks=unique(df$x))+
scale_L_continuous(breaks=unique(df$y))+
scale_R_continuous(breaks=unique(df$z))
我们先存储原图:
library(ggtern)
g = ggtern(data=df,aes(x=Cond1,y=Cond2,z=Cond3,color=func1)) +
theme_bw() +
geom_point() +
labs(x="Cond1",y="Cond2",z="Cond3") +
scale_T_continuous(breaks=unique(df$x))+
scale_L_continuous(breaks=unique(df$y))+
scale_R_continuous(breaks=unique(df$z))
使用 geom_label_viewport()
选项的简单注释图如下所示:
g + geom_text(aes(label=func2),hjust=-0.2,vjust=-0.2,size=3)
您可以像这样将点子集化为标签:
g + geom_text(data=~subset(.,func2 %in% c("C2","B1")),
aes(label=func2),hjust=-0.2,vjust=-0.2,size=3)
我想将我的数据绘制成三元图,其中基因在三种条件之一下上升或下降,即。更接近显示更高值的条件。
- 每个变量的值是否独立于值进行标准化?
- 我可以为选定的“基因”变量添加一个标签,该变量表示变量“func2”吗?
这是我获得的(顶部)和我想要的(底部)的可重现示例
gene <- c("Gene1", "Gene2", "Gene3", "Gene4","Gene5", "Gene6")
func1 <- c("A", "B", "C", "D", "C", "A")
func2 <- c("A1", "B1", "C1", "D1", "C2", "A2")
Cond1 <- c(0.007623561, 0.004639893, 0.000994121, 0.017494429, 0.000366445, 0.006663334)
Cond2 <- c(0.011299941, 0.009994388, 0.001012428, 0.013695669, 0.000299771, 0.010287904)
Cond3 <- c(0.005055458, 0.016826251, 0.001311254, 0.016115009, 0.000242897, 0.004583889)
df <- data.frame(gene, func1, func2, Cond1, Cond2, Cond3)
library(ggplot2)
library(ggtern)
ggtern(data=df,aes(x=Cond1,y=Cond2,z=Cond3,color=func1)) +
theme_bw() +
geom_point() +
labs(x="Cond1",y="Cond2",z="Cond3") +
scale_T_continuous(breaks=unique(df$x))+
scale_L_continuous(breaks=unique(df$y))+
scale_R_continuous(breaks=unique(df$z))
我们先存储原图:
library(ggtern)
g = ggtern(data=df,aes(x=Cond1,y=Cond2,z=Cond3,color=func1)) +
theme_bw() +
geom_point() +
labs(x="Cond1",y="Cond2",z="Cond3") +
scale_T_continuous(breaks=unique(df$x))+
scale_L_continuous(breaks=unique(df$y))+
scale_R_continuous(breaks=unique(df$z))
使用 geom_label_viewport()
选项的简单注释图如下所示:
g + geom_text(aes(label=func2),hjust=-0.2,vjust=-0.2,size=3)
您可以像这样将点子集化为标签:
g + geom_text(data=~subset(.,func2 %in% c("C2","B1")),
aes(label=func2),hjust=-0.2,vjust=-0.2,size=3)