我想根据数据集中的另一个变量来改变热力图轴标签的颜色。目前我尝试了以下方法:
#load data, scale numeric columns, add state abbreviation and region
state_data <- data.frame(state.x77)
state_data <- state_data[,1:8]
state_data <- rescaler(state_data, type='range')
state_data$State <- state.abb
state_data$Region <- state.region
#make heatmap
melted_state <- melt(state_data,id.vars=c('State', 'Region'))
p <- ggplot(melted_state,
aes(x=State, y=variable))
p <- p + geom_tile(aes(fill = value), colour = "white")
p <- p + theme(axis.text.x=element_text(colour="Region")) ## doesn't work!
p
我遇到了这个错误: 在 grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : 非法的颜色名称 'Region'
如果我去掉 'Region' 周围的引号,我会得到以下错误:
Error in structure(list(family = family, face = face, colour = colour, :
object 'Region' not found
我该怎么做呢?
ggplot2
作者没有考虑到的一种灵活性轴,因此可能很难实现。 - Ben Bolker