2017-08-23 35 views
1

我想知道是否可以更改由gplots包生成的气球图的行和列注释。从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)任意颜色?例如,我想要红,蓝,绿,蓝,蓝,绿,蓝,蓝,绿,蓝,蓝三种颜色。

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

感谢

回答

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) 

enter image description here

+0

感谢您的帮助! – pisistrato