是什么让 geom_point 上的点图重叠?以及如何改变它?
What makes a dot plot on top of another on geom_point? And how to change it?
是什么让值点图重叠并在 ggtern 图上绘制在另一个之上?我该如何改变它?
我想将我选择的彩色观察结果绘制在黑色观察结果之上。 (根据我的数据,我有 1400 个观察结果,即使点尺寸较小,这种情况仍然会发生)
obs <- 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(obs, func1, func2, Cond1, Cond2, Cond3)
col<-rep("black", length(unique(df$func1)))
names(col) <- unique(df$func1)
col[which(names(col)=="A")] <- 'red'
col[which(names(col)=="D")] <- 'blue'
library(ggtern)
g <- ggtern(data=df, aes(x=Cond1,y=Cond2,z=Cond3)) +
theme_bw() +
geom_point(aes(fill=func1), shape=21, size = 20, colour="black") +
scale_fill_manual(values=col) +
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))
print(g)
现在:
我试过将颜色更改为 'white' col<-rep("white", length(unique(df$func1)))
或者另一种选择是制作黑点 white/transparent?在 col
?
也许使“B”和“C”透明可以解决您的问题,例如
library(tidyverse)
obs <- 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(obs, func1, func2, Cond1, Cond2, Cond3)
col<-rep("black", length(unique(df$func1)))
names(col) <- unique(df$func1)
col[which(names(col)=="A")] <- 'red'
col[which(names(col)=="D")] <- 'blue'
col[which(names(col)=="B" | names(col)=="C")] <- 'transparent'
#install.packages("ggtern")
library(ggtern)
g <- ggtern(data=df, aes(x=Cond1,y=Cond2,z=Cond3)) +
theme_bw() +
geom_point(aes(fill=func1), shape=21, size = 20, colour="black") +
scale_fill_manual(values=col) +
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))
print(g)
否则,您可以像这样指定绘图顺序(根据 controlling order of points in ggplot2 in R?):
library(tidyverse)
obs <- 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(obs, func1, func2, Cond1, Cond2, Cond3)
col<-rep("black", length(unique(df$func1)))
names(col) <- unique(df$func1)
col[which(names(col)=="A")] <- 'red'
col[which(names(col)=="D")] <- 'blue'
#install.packages("ggtern")
library(ggtern)
library(tidyverse)
g <- ggtern(data=df, aes(x=Cond1,y=Cond2,z=Cond3)) +
theme_bw() +
geom_point(data = subset(df, !(func1 %in% c("A", "D"))),
aes(fill=func1), shape=21, size = 20, colour="black") +
geom_point(data = subset(df, func1 %in% c("A", "D")),
aes(fill=func1), shape=21, size = 20, colour="black") +
scale_fill_manual(values=col) +
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))
print(g)
是什么让值点图重叠并在 ggtern 图上绘制在另一个之上?我该如何改变它? 我想将我选择的彩色观察结果绘制在黑色观察结果之上。 (根据我的数据,我有 1400 个观察结果,即使点尺寸较小,这种情况仍然会发生)
obs <- 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(obs, func1, func2, Cond1, Cond2, Cond3)
col<-rep("black", length(unique(df$func1)))
names(col) <- unique(df$func1)
col[which(names(col)=="A")] <- 'red'
col[which(names(col)=="D")] <- 'blue'
library(ggtern)
g <- ggtern(data=df, aes(x=Cond1,y=Cond2,z=Cond3)) +
theme_bw() +
geom_point(aes(fill=func1), shape=21, size = 20, colour="black") +
scale_fill_manual(values=col) +
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))
print(g)
现在:
我试过将颜色更改为 'white' col<-rep("white", length(unique(df$func1)))
或者另一种选择是制作黑点 white/transparent?在 col
?
也许使“B”和“C”透明可以解决您的问题,例如
library(tidyverse)
obs <- 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(obs, func1, func2, Cond1, Cond2, Cond3)
col<-rep("black", length(unique(df$func1)))
names(col) <- unique(df$func1)
col[which(names(col)=="A")] <- 'red'
col[which(names(col)=="D")] <- 'blue'
col[which(names(col)=="B" | names(col)=="C")] <- 'transparent'
#install.packages("ggtern")
library(ggtern)
g <- ggtern(data=df, aes(x=Cond1,y=Cond2,z=Cond3)) +
theme_bw() +
geom_point(aes(fill=func1), shape=21, size = 20, colour="black") +
scale_fill_manual(values=col) +
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))
print(g)
否则,您可以像这样指定绘图顺序(根据 controlling order of points in ggplot2 in R?):
library(tidyverse)
obs <- 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(obs, func1, func2, Cond1, Cond2, Cond3)
col<-rep("black", length(unique(df$func1)))
names(col) <- unique(df$func1)
col[which(names(col)=="A")] <- 'red'
col[which(names(col)=="D")] <- 'blue'
#install.packages("ggtern")
library(ggtern)
library(tidyverse)
g <- ggtern(data=df, aes(x=Cond1,y=Cond2,z=Cond3)) +
theme_bw() +
geom_point(data = subset(df, !(func1 %in% c("A", "D"))),
aes(fill=func1), shape=21, size = 20, colour="black") +
geom_point(data = subset(df, func1 %in% c("A", "D")),
aes(fill=func1), shape=21, size = 20, colour="black") +
scale_fill_manual(values=col) +
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))
print(g)