faithfuld , . , . geom_raster, . x, y, . , y, y ( ), . :
library(ggplot2)
library(gridExtra)
g1 <- ggplot(faithfuld, aes(x=waiting, y=eruptions)) +
geom_point(size=0.5)
g2 <- ggplot(faithfuld, aes(x=waiting, y=log(eruptions))) +
geom_point(size=0.5)
grid.arrange(g1, g2, ncol=2)

y , faithful geom_density_2d.
ggplot(faithful, aes(x=waiting, y=log(eruptions))) +
geom_density_2d() +
stat_density_2d(geom="raster", aes(fill=..density..),
contour=FALSE)

: geom_rect xmin, xmax, ymin, ymax, .
geom_raster , , , geom_tile geom_rect . , , () , xmin xmax , .
dat <- data.frame(x = rep(1:10, 10),
y = unlist(lapply(1:10, function(i) rep(i, 10))),
z = faithfuld$density[1:100])
library(ggplot2)
library(gridExtra)
g <- ggplot(dat, aes(x = log(x), y = y, fill = z)) +
geom_raster()
distance <- diff((unique(dat$x)))/2
upper <- (unique(dat$x)) + c(distance, distance[length(distance)])
lower <- (unique(dat$x)) - c(distance[1], distance)
dat$xmin <- dat$x - 0.5
dat$xmax <- dat$x + 0.5
dat$ymin <- unlist(lapply(lower, function(i) rep(i, rle(dat$y)$lengths[1])))
dat$ymax <- unlist(lapply(upper, function(i) rep(i, rle(dat$y)$lengths[1])))
g2 <- ggplot(dat, aes(x=log(x), y=y, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, fill=z)) +
geom_rect()
grid.arrange(g, g2, ncol=2)
