2

I am using the ggtern package in R for plotting the ternary diagrams. I have trouble customizing the legend of the 'fill'. Here is my code:

library(ggtern)
setwd("~/R/data")
library(XLConnect)
df <- readWorksheetFromFile("ternary_two_wells.xlsx",sheet=1,startRow = 1, endCol=7)
# Feldspar = Feldspar[with(Feldspar, order(-P.Gpa)), ]
df = df[with(df,order(-ReTOC)), ]
# Build and Render the Plot
ggtern(data = df, aes(x = Silicate, y = Carbonate, z = Clay)) +
  #the layer
  geom_point(aes(fill = Permeability,
                 size = ReTOC,
                 shape = Well)) +
  #scales
  scale_shape_manual(values = c(21, 24)) +
  scale_size_continuous(range = c(2.5, 7.5)) +
  scale_fill_gradient(low = 'green', high = 'red') +

  #theme tweaks
  theme_bw()  +
  theme(legend.position      = c(0, 1),
        legend.justification = c(0, 1),
        legend.box.just      = 'left') +
  #tweak guides
  guides(shape= guide_legend(order   =1,
                             override.aes=list(size=5)),
         size = guide_legend(order   =2),
         fill = guide_colourbar(order=3)) +

  #labels and title
  labs(size = 'ReTOC/%BV',
       fill = 'Permeability/nD') +
  ggtitle('Two Encana Wells')

Here is how the resulting ternary diagram looks like: enter image description here See the 'Permeability/nD' legend? That is in scientific notation. How do I get it to show values in decimal instead?

Bharat
  • 2,409
  • 6
  • 32
  • 57
  • One option is to use package scales and `labels = comma` in `scale_fill_gradient`. See [here](http://stackoverflow.com/questions/14563989/force-r-to-stop-plotting-abbreviated-axis-labels-e-g-1e00-in-ggplot2) and [here](http://stackoverflow.com/questions/11610377/how-do-i-change-the-formatting-of-numbers-on-an-axis-with-ggplot) for examples. – aosmith Jul 27 '16 at 16:02
  • Thank you. That worked. How do I accept you answer? It appears as a comment! There is no acceptance button or check mark here :) – Bharat Jul 27 '16 at 16:36

1 Answers1

1

You can use package scales and the labels argument in scale_fill_gradient to use commas instead of scientific notation.

library(scales)

scale_fill_gradient(low = 'green', high = 'red', labels = comma) 
aosmith
  • 34,856
  • 9
  • 84
  • 118