color scale support for geom_hex_tern?

Issue #5 new
Former user created an issue

Hi Nicholas. I am using v2.2.2 for internal documentation supporting an FDA submission, in particular the new geom_hex_tern geometry.

Any plans on allowing the colorscale to be user controlled? Adding a scale_color_gradient command has no effect on the hexbin plot.

Many thanks, John Szumiloski

Comments (1)

  1. Nicholas Hamilton repo owner

    John,

    It works fine, but you need to assign it to the summary statistic for each hex bin:

    Here are two examples, for fill and for colour, respectively.

    library(ggtern)
    
    set.seed(1)
    n  = 1000
    df = data.frame(x  = runif(n),
                    y  = runif(n),
                    z  = runif(n),
                    wt = runif(n))
    
    #Colour
    ggtern(df,aes(x,y,z)) + 
      geom_hex_tern(binwidth=0.1,fill='white',aes(color=..stat..)) +
      scale_color_gradient(low='green',high='red')
    
    #Fill
    ggtern(df,aes(x,y,z)) + 
      geom_hex_tern(binwidth=0.1,colour='black',aes(fill=..stat..)) +
      scale_fill_gradient(low='green',high='red')
    

    Have I misunderstood what you are seeking?

    Cheers,

    NH

  2. Log in to comment