Transform color scale, but keep a nice legend with ggplot2

前端 未结 1 943
醉梦人生
醉梦人生 2020-12-29 08:30

I have seen somewhat similar questions to this, but I\'d like to ask my specific question as directly as I can:

I have a scatter plot with a \"z\" variable encoded i

相关标签:
1条回答
  • 2020-12-29 09:07

    Have a look at the package scales especially ?trans

    I think that a transformation that maps the colour given the probability of getting the value or more extreme should be reasonable (basically pnorm(z))

    I think that scale_colour_continuous(trans = probability_trans(distribution = 'norm') should work, but it throws warnings.

    So I defined a new transformation (see ?trans_new)

    I have to define a transformation and an inverse

    library(scales)
    norm_trans <- function(){
      trans_new('norm', function(x) pnorm(x), function(x) qnorm(x))
    }
    
    badVersion + geom_point() + scale_colour_continuous(trans = 'norm'))
    

    enter image description here

    Using the supplied probability_trans throws a warning and doesn't seem to work

    # this throws a warning
    badVersion + geom_point+
      scale_colour_continuous(trans = probability_trans(distribution = 'norm'))
    
    ## Warning message:
    ## In qfun(x, ...) : NaNs produced
    

    enter image description here

    0 讨论(0)
提交回复
热议问题