1
我有一个包含很多行(成千上万个城市)的热图,为了清楚起见,我只想显示其中几个的名称。我仍然想要展示整个热图,因为颜色可以让人了解这种情况(城市名称并不重要,但我想为了教学目的展示其中的一些)。隐藏一些热图贴图文本
library(ggplot2)
n <- 15
c.1 <- c(rep(x="Summer", times=n), rep(x="Winter", times=n))
c.2 <- c(rep(x="Dallas", times=n/5), rep(x="Seattle", times=n/5), rep(x="Atlanta", times=n/5), rep(x="Chicago", times=n/5), rep(x="Boston", times=n/5))
c.3 <- c("Morning", "Midday", "Evening")
to.plot <- data.frame(cbind(c.1, c.2, c.3))
to.plot$value <- sample(rep(x=c("Bad", "Average", "Good"), times=100), 10)
colnames(to.plot) <- c("Season", "City", "Time", "value")
to.plot$City <- factor(to.plot$City, levels=c("Seattle", "Chicago", "Dallas", "Atlanta", "Boston"), ordered=TRUE)
p <- ggplot(to.plot, aes(x=Season, y=City))
p <- p + geom_tile(aes(fill=value), colour="white")
p <- p + scale_fill_manual(values=c("red", "green", "yellow"))
p <- p + theme(legend.position = "none", axis.text.x=element_text(angle=90, 8))
p <- p + facet_grid(. ~ Time)
p <- p + theme(legend.position = "none")
print(p)
在这个例子中,情节,只有五个城市很容易看到所有五个城市的名字,但与上千个城市的真实的例子,他们模糊起来。
我怎样才能看到完全相同的热图,但只显示三分之一左右的城市名称?我包括有序的因素,因为顺序与情节可视化相关(因式分解可能是为什么我有问题,但因子顺序必须在那里)。
谢谢,就是这样。因素顺序好。 – Chris 2013-05-07 22:41:08