【问题标题】:specifying number of breaks with scales in ggplot2 without a transform?在没有变换的情况下在 ggplot2 中指定带刻度的中断数?
【发布时间】:2013-03-31 19:24:00
【问题描述】:

如果我希望我的数据轴有更多的中断但没有对值进行转换,我该如何在 ggplot2 中做到这一点?例如:

... + scale_x_continuous(breaks=scales.trans_breaks("log2", function(x) 2^x, n=8),   limits=limits)

如果您希望转换数据并且n= 参数可以让您说出中断的次数,则可以使用。如何在不转换数据的情况下指定中断?你只是给它一个身份功能吗?

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    我不希望根据数据中的计算给出明确的刻度,因此我希望 ggplot2 仅在给定限制和刻度数的情况下为我选择刻度线。这段代码对我有用:

     library(scales)
     scale_x_continuous(breaks = trans_breaks(identity, identity, n = numticks))
    

    当然,您始终可以使用 breaks = ... 明确设置刻度线,就像 agstudy 所写的那样。

    【讨论】:

    • 由于您没有使用任何转换,您不妨使用pretty_breaks 而不是trans_breaks
    【解决方案2】:

    你可以给scale_x_continuous一个这样的中断向量:

    n=5
    breaks = seq(min(dat$x),max(dat$x), length.out = n)
    m + scale_x_continuous(breaks=breaks)
    

    【讨论】:

    • 我知道,但我不想指定中断值,只指定数字
    猜你喜欢
    • 2013-03-25
    • 1970-01-01
    • 2020-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-19
    • 1970-01-01
    相关资源
    最近更新 更多