1

I was experimenting with this code and what I found interesting is that the number of ticks changed when I plotted. In my case I get this:

enter image description here

The code used is the same as in the OP:

#Orignal Data as per Question
a <- c(0.1, 0.5,0.5, 0.6, 0.2, 0          , 0         , 0.004166667, 0.45) 
b <- c(0.75,0.5,0  , 0.1, 0.2, 0.951612903,0.918103448, 0.7875     , 0.45)
c <- c(0.15,0  ,0.5, 0.3, 0.6, 0.048387097,0.081896552, 0.208333333, 0.10) 
d <- c(500,2324.90,2551.44,1244.50, 551.22,-644.20,-377.17,-100, 2493.04) 
df <- data.frame(a, b, c, d)

#For labelling each point.
df$id <- 1:nrow(df)

#Build Plot
ggtern(data=df,aes(x=c,y=a,z=b),aes(x,y,z)) + 
  stat_density2d(geom="polygon",
                 n=400,
                 aes(fill=..level..,
                 weight=d,
                 alpha=abs(..level..)),
                 binwidth=100) + 
  geom_density2d(aes(weight=d,color=..level..),
                 n=400,
                 binwidth=100) +
  geom_point(aes(fill=d),color="black",size=5,shape=21) + 
  geom_text(aes(label=id),size=3) + 
  scale_fill_gradient(low="yellow",high="red") + 
  scale_color_gradient(low="yellow",high="red") + 
  theme_tern_rgbw() + 
  theme(legend.justification=c(0,1), legend.position=c(0,1)) + 
  guides(fill = guide_colorbar(order=1),
         alpha= guide_legend(order=2),
         color="none") + 
  labs(  title= "Ternary Plot and Filled Contour",
         fill = "Value, V",alpha="|V - 0|")

#Save Plot
ggsave("TernFilled.png")

I have been trying to increase the number of ticks to 11, but no luck. How can the number of ticks be specified?

Multi color gradient

And is it possible to multi color gradient instead of two color gradient? I tried setting

scale_fill_gradient(low="yellow",high="red")

to

scale_fill_gradient(low="blue", mid = "yellow",  high="red")

but there was no change. How can it be done?

Community
  • 1
  • 1
Tom Kurushingal
  • 6,086
  • 20
  • 54
  • 86

1 Answers1

0

ggtern 2.0.1, which was published on CRAN a couple of days ago after completely re-writing the package to be compatible with ggplot2 2.0.0. A summary of the new functionality in ggtern 2.0.X can be found here:

So in regards to the number of ticks, unless they are explicitly specified via the 'breaks' argument in each scale_X_continuous(...) [where X = T, L or R], or via limit_tern(...), where the same 'breaks' argument gets passed to all three continuous scales, ggtern will try to make a best guess.

Consider the following set of examples:

#Set up a plot
df   = data.frame(x=1,y=1,z=1)
base = ggtern(data=df,aes(x,y,z)) + geom_point()

#1. The default case, best guess.
base 

#2. A reduced scale limit, with best guess.
base + limit_tern(.5,.5,.5)

#3. Manual breaks passed to all three ternary scales
base + limit_tern(breaks = seq(0,1,by=0.05))

#4. Manual breaks passed to all three ternary scales, under limited region
base + limit_tern(.5,.5,.5,breaks = seq(0,1,by=0.05))

#5. Manual breaks passed to a single ternary scale, the other two are done by best guess
base + scale_T_continuous(breaks  = seq(0,1,by=0.05))
Nicholas Hamilton
  • 10,044
  • 6
  • 57
  • 88