【问题标题】:ggplot2: how to plot in reciprocal scaleggplot2:如何以倒数比例绘制
【发布时间】:2012-05-10 06:05:11
【问题描述】:

我想使用 ggplot 创建散点图,其中 y 缩放为 1/y(我的 y 都是正数),但标有 y 的原始值。我怎样才能做到这一点?

我尝试使用+ scale_y_continuous(trans='recip') 进行绘图,但出现以下错误:

get(as.character(FUN), mode = "function", envir = envir) 中的错误:
找不到模式“功能”的对象“recip_trans”

谢谢,

【问题讨论】:

  • ?scales::reciprocal_trans 可能就是您要找的。​​span>
  • 图书馆(秤)...对吗?现在我正在尝试显示比例,我只是在没有任何比例的情况下反转了数字。我的原始值从 700 到 5000 不等。所以我想画 500、1000、2000、5000 之类的线。

标签: r ggplot2


【解决方案1】:

这样的?

library(ggplot2)
library(scales)

df = data.frame(x = c(1:46), y = seq(500, 5000, 100))

ggplot(df, aes(x, y)) +
   geom_point() +
    scale_y_continuous(trans = reciprocal_trans(), breaks = c(500, 1000, 2000, 5000))

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-15
  • 1970-01-01
  • 1970-01-01
  • 2013-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多