【问题标题】:Ternary Diagram How to make the legend labels in decimal instead of scientific notation [duplicate]三元图如何以十进制而不是科学计数法制作图例标签[重复]
【发布时间】:2016-12-01 17:46:58
【问题描述】:

我正在使用 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')

生成的三元图如下所示: 看到“渗透率/nD”图例了吗?那是科学计数法。如何让它以十进制显示值?

【问题讨论】:

  • 一种选择是在scale_fill_gradient 中使用包比例和labels = comma。有关示例,请参阅 herehere
  • 谢谢。那行得通。我如何接受你的回答?它显示为评论!这里没有接受按钮或复选标记:)

标签: r ggplot2 legend-properties ggtern


【解决方案1】:

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

library(scales)

scale_fill_gradient(low = 'green', high = 'red', labels = comma) 

【讨论】:

    猜你喜欢
    • 2018-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-17
    • 2016-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多