【问题标题】:ggplot2 plotmatrix - changing text labelsggplot2 plotmatrix - 更改文本标签
【发布时间】:2011-04-19 00:17:19
【问题描述】:

我在 ggplot2 (ggplot2_0.8.8) 中使用plotmatrix 函数,并希望覆盖从我的数据框中显示的列名,例如

plotmatrix(mtcars) + opts(strip.text.x = theme_text(size=20))

我可以使用 opts 更改 strip.text.x 和 strip.text.y 的属性,但是我可以在哪里更改文本本身,例如我想将“mpg”替换为“Miles / Gallon”,这会导致作为 colname 的问题。我认为facet_grid 中可能有类似labeller 的选项,它允许我用任意文本替换现有的列名?

【问题讨论】:

    标签: r plot ggplot2 lattice


    【解决方案1】:

    重命名列。

    x <- mtcars ## just because I like x.
    colnames(x)[1] <- "Miles/Gallon" ## rename all by dropping [1] and using c(...)
    plotmatrix(x) + opts(strip.text.x = theme_text(size=20))
    

    【讨论】:

    • 是的,创建第二个临时数据框来保存图形数据可能是最简单的方法。我担心稍后在代码中通过 dataframe$colname 语法搞砸引用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多