2

What makes a value-dot plot overlap and plot on top of another on the ggtern plot? And how can I change it? I would like to have my selected coloured observations plotted on top of the black ones. (On my data I have 1400 observations and even with lower dot size this still happens)

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)

Now: enter image description here

I have tried changing colour to 'white' col<-rep("white", length(unique(df$func1))) or another option would be making the black dots white/transparent? in col?

Ecg
  • 908
  • 1
  • 10
  • 28

1 Answers1

1

Perhaps making "B" and "C" transparent would solve your problem, e.g.

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)

example.png

Otherwise, you can specify the order of plotting like this (per 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)

example2.png

jared_mamrot
  • 22,354
  • 4
  • 21
  • 46
  • Hey @jared_mamrot the problem I will find with my data is that "B" and "C" are actually not 2 but 400 observations, so would it be a way of suggesting something like: anything but A, B go transparent? – Ecg Nov 01 '20 at 23:26
  • 1
    Right, so making them transparent probably wouldn't be ideal - I've updated my answer again – jared_mamrot Nov 01 '20 at 23:27
  • DO you mean, that but for A, D? – Ecg Nov 01 '20 at 23:35
  • Yes, I see the edited post now, makes sense, let me try it out ;) – Ecg Nov 01 '20 at 23:35