2016-07-27 69 views
2

我在R中使用ggtern包来绘制三元图。我无法自定义“填充”的图例。这里是我的代码:三元图如何使十进制代替科学计数法制作图例标签

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') 

下面是导致三元相图的样子: enter image description here 见“渗透性/ ND”传奇?这是科学记数法。我如何让它显示十进制值而不是?

+0

一种选择是在scale_fill_gradient中使用包标度和'labels =逗号'。见[这里](http://stackoverflow.com/questions/14563989/force-r-to-stop-plotting-abbreviated-axis-labels-eg-1e00-in-ggplot2)和[here](http://例如:stackoverflow.com/questions/11610377/how-do-i-change-the-formatting-of-numbers-on-an-axis-with-ggplot)。 – aosmith

+0

谢谢。这工作。我如何接受你的回答?它显示为一条评论!这里没有验收按钮或复选标记:) – Bharat

回答

1

您可以使用包比例尺scale_fill_gradient中的参数labels来使用逗号而不是科学记数法。

library(scales) 

scale_fill_gradient(low = 'green', high = 'red', labels = comma) 
相关问题