【问题标题】:scale_alpha_continuous on log scalescale_alpha_continuous 对数刻度
【发布时间】:2020-09-01 10:03:00
【问题描述】:

我正在尝试在对数刻度上使用 ggplot 中的 scale_alpha_continuous 来生成一个图形,其透明度(和颜色)根据对数刻度上的给定值而变化,给定广泛的分布。 使用下面的代码,我可以通过添加trans="log" 来根据对数比例更改颜色,但我如何对透明度(alpha)做同样的事情?

p+scale_color_continuous(trans = "log",low="red", high="black")+ scale_alpha_continuous(range = c(0.1, 1))

非常感谢!

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    您也可以将trans = "log" 添加到scale_alpha_continuous()

    library(ggplot2)
    # here is some simulated data
    set.seed(2020)
    df <- data.frame(X = rnorm(100),
                     Y = runif(100),
                     Z = rexp(100, rate = 0.0000001))
    # Original plot
    df %>%
      ggplot(aes(x = X, y = Y, color = Z, alpha = Z)) +
      geom_point(size = 5)
    

    # Log scales
    df %>%
      ggplot(aes(x = X, y = Y, color = Z, alpha = Z)) +
      geom_point(size = 5) + 
      scale_alpha_continuous(trans = "log", breaks = c(4e5, 4e6, 4e7)) +
      scale_color_continuous(trans = "log", breaks = c(4e5, 4e6, 4e7))
    

    【讨论】:

      猜你喜欢
      • 2012-12-03
      • 2013-01-09
      • 2011-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-07
      • 2014-03-22
      相关资源
      最近更新 更多