【问题标题】:Inserting labels in box plot in R on a 45 degree angle?以 45 度角在 R 中的箱形图中插入标签?
【发布时间】:2017-11-14 03:58:12
【问题描述】:

boxplot() 命令中是否有任何方法可以将标签旋转 45 度角?

我意识到 las=2 命令将它们旋转到垂直于 x 轴,但我希望它们处于 45 度角。

【问题讨论】:

    标签: r


    【解决方案1】:

    以下内容如何:

    # Some sample data
    x <- list(x = rnorm(100, 2), y = rnorm(100, 4));
    # Plot without x axis
    boxplot(x, xaxt = "n");
    # Add axis labels rotated by 45 degrees
    text(seq_along(x), par("usr")[3] - 0.5, labels = names(x), srt = 45, adj = 1, xpd = TRUE);
    


    PS。或者在ggplot 中更简单/更干净:

    require(ggplot2);
    require(reshape2);
    df <- melt(x);
    ggplot(df, aes(L1, value)) + geom_boxplot() + theme(axis.text.x = element_text(angle = 45, hjust = 1));
    

    【讨论】:

    猜你喜欢
    • 2020-08-23
    • 2014-02-12
    • 2013-12-13
    • 2018-02-22
    • 2018-11-07
    • 2017-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多