【问题标题】:Create annotation for a balloon plot from gplots package从 gplots 包为气球图创建注释
【发布时间】:2018-01-31 19:44:45
【问题描述】:

我想知道是否可以更改由 gplots 包生成的气球图的行和列注释。

假设我的数据是 mtcars 数据集的子集

data(mtcars)
dt <- as.table(as.matrix(mtcars[1:10,]))

我可以制作如下气球图

library("gplots")
balloonplot(t(dt), xlab ="", ylab="", label = FALSE, show.margins = FALSE)

我可以用任意颜色更改灰色条的颜色(x 和 y)吗?例如,我想要红色的 mpg、cyl、disp 和 drat,其他的都是蓝色。

这可能吗?或者我需要看看另一个包?

谢谢

【问题讨论】:

    标签: r contingency balloon gplots


    【解决方案1】:

    下载myballoonplot.rhere并将其保存在您的工作目录中。
    然后,运行以下代码:

    data(mtcars)
    dt <- as.table(as.matrix(mtcars[1:10,]))
    
    source("myballoonplot.r")
    
    # Define colors for y bars 
    col.bar.y <- rep("lightgray",ncol(dt))
    col.bar.y[colnames(dt) %in% c("mpg","cyl","disp","drat")] <- "red"
    
    # Define colors for x bars     
    col.bar.x <- rep("lightgray",nrow(dt))
    col.bar.x[rownames(dt) %in% c("Mazda RX4","Valiant","Duster 360")] <- "green"
    col.bar.x[rownames(dt) %in% c("Datsun 710")] <- "#0000FF77"
    
    # Plot using the modified version of balloonplot
    myballoonplot.table(t(dt), xlab ="", ylab="", label = FALSE, 
        show.margins = FALSE, col.bar.y = col.bar.y, col.bar.x = col.bar.x)
    

    【讨论】:

    • 感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-07
    • 1970-01-01
    • 1970-01-01
    • 2021-03-05
    • 2013-11-03
    • 2012-02-12
    • 1970-01-01
    相关资源
    最近更新 更多