Fill by geom_point and black outline in a ggtern

You need to create a named list of colors and then use the scale_fill_manual function.

#A General way of creating a name list of colors
# col<-c("A" = "red", "B"="black", "C"="black", "D"="blue")
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, 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)    

Update
ggplot plots the different layers in order that they are defined. In order to plot the A & D points on top of the other points, one can add another geom_point definition after the original one.

Here I created a subset of the A&D points and plotted them over the initial set.

df_ad <- df[(df$func1=="A" | df$func1=="D"),]

ggtern(data=df, aes(x=Cond1,y=Cond2,z=Cond3)) +
   theme_bw() +
   geom_point(aes(fill=func1), shape=21, colour="black" ) +
   geom_point(data=df_ad, aes(x=Cond1,y=Cond2,z=Cond3, fill=func1), shape=21) +
   scale_fill_manual(values=col) #+ ....
   

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top