geom_tile(ggplot2)
geom_tile()所属R语言包:ggplot2
Tile plane with rectangles.
瓷砖矩形平面。
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Similar to levelplot and image.
类似levelplot和image。
用法----------Usage----------
geom_tile(mapping = NULL, data = NULL, stat = "identity",
position = "identity", ...)
参数----------Arguments----------
参数:mapping
The aesthetic mapping, usually constructed with aes or aes_string. Only needs to be set at the layer level if you are overriding the plot defaults.
构建的审美映射,通常用aes或aes_string。仅需要设置层级别,如果你是压倒一切的图预设值。
参数:data
A layer specific dataset - only needed if you want to override the plot defaults.
一层特定的数据集 - 只需要如果你想覆盖默认的图。
参数:stat
The statistical transformation to use on the data for this layer.
这一层的数据统计变换使用。
参数:position
The position adjustment to use for overlappling points on this layer
在这一层上使用overlappling点位置调整
参数:...
other arguments passed on to layer. This can include aesthetics whose values you want to set, not map. See layer for more details.
其他参数传递给layer。这可以包括美学要将其值设置,而不是图。见layer更多详情。
实例----------Examples----------
# Generate data[生成数据]
pp <- function (n,r=4) {
x <- seq(-r*pi, r*pi, len=n)
df <- expand.grid(x=x, y=x)
df$r <- sqrt(df$x^2 + df$y^2)
df$z <- cos(df$r^2)*exp(-df$r/6)
df
}
p <- ggplot(pp(20), aes(x=x,y=y))
p + geom_tile() #pretty useless![漂亮也没用!]
# Add aesthetic mappings[审美映射]
p + geom_tile(aes(fill=z))
# Change scale[改变规模]
p + geom_tile(aes(fill=z)) + scale_fill_gradient(low="green", high="red")
# Use qplot instead[qplot,而不是使用]
qplot(x, y, data=pp(20), geom="tile", fill=z)
qplot(x, y, data=pp(100), geom="tile", fill=z)
# Missing values[遗漏值]
p <- ggplot(pp(20)[sample(20*20, size=200),], aes(x=x,y=y,fill=z))
p + geom_tile()
# Input that works with image[输入与图像]
image(t(volcano)[ncol(volcano):1,])
library(reshape2) # for melt[为融化]
ggplot(melt(volcano), aes(x=Var1, y=Var2, fill=value)) + geom_tile()
# inspired by the image-density plots of Ken Knoblauch[灵感来自肯的Knoblauch的图像密度图]
cars <- ggplot(mtcars, aes(y=factor(cyl), x=mpg))
cars + geom_point()
cars + stat_bin(aes(fill=..count..), geom="tile", binwidth=3, position="identity")
cars + stat_bin(aes(fill=..density..), geom="tile", binwidth=3, position="identity")
cars + stat_density(aes(fill=..density..), geom="tile", position="identity")
cars + stat_density(aes(fill=..count..), geom="tile", position="identity")
# Another example with with unequal tile sizes[另一个例子与不平等的瓷砖尺寸]
x.cell.boundary <- c(0, 4, 6, 8, 10, 14)
example <- data.frame(
x = rep(c(2, 5, 7, 9, 12), 2),
y = factor(rep(c(1,2), each=5)),
z = rep(1:5, each=2),
w = rep(diff(x.cell.boundary), 2)
)
qplot(x, y, fill=z, data=example, geom="tile")
qplot(x, y, fill=z, data=example, geom="tile", width=w)
qplot(x, y, fill=factor(z), data=example, geom="tile", width=w)
# You can manually set the colour of the tiles using[您可以手动设置颜色的瓷砖使用]
# scale_manual[scale_manual]
col <- c("darkblue", "blue", "green", "orange", "red")
qplot(x, y, fill=col[z], data=example, geom="tile", width=w, group=1) + scale_fill_identity(labels=letters[1:5], breaks=col)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|