加载ggmap包后,执行
ggimage(hadley)
会出现一张Hadley的图像,这张图像尝试自己做一下,但是尝试了很多再次都失败了
效果图,原始图片
library(EBImage)
library(ggplot2)
library(reshape)
image <- readImage('Hadley.jpg')
theme_set(theme_bw())
gimage <- function(image){
require(ggplot2)
# remove first pound for the image in the case study
if(length(dim(image)) == 2){
message('creating black and white image...')
image <- melt(image)
names(image) <- c('row','column','fill')
plot <- qplot(column, -row, data = image, geom = 'tile', fill = fill) +
scale_fill_gradient(low = 'black', high = 'white')
}
if(length(dim(image)) == 3){
message('creating color image...')
image <- apply(image,1:2,function(v)rgb(v[1],v[2],v[3]))
image <- melt(image)
plot <- ggplot(image, aes(row, -column, fill=fill)) + geom_tile() + scale_fill_identity()
}
plot +
theme(
axis.line = element_line(), axis.ticks = element_line(),
axis.text.x = element_text(), axis.text.y = element_text(),
axis.title.x = element_text(), axis.title.y = element_text(),
axis.ticks.length = unit(0, "lines"),
axis.ticks.margin = unit(0, "lines"),
legend.position = "none",
panel.background = element_rect(),
panel.border = element_rect(),
panel.grid.major = element_line(),
panel.grid.minor = element_line(),
panel.margin = unit(0, "lines"),
plot.background = element_rect(),
plot.title = element_text(),
plot.margin = unit(c(-1, -1, -1.5, -1.5), "lines")
)
}
gimage(image)
总是报错:Don't know how to automatically pick scale for object of type function. Defaulting to continuous.
Error in FUN(X[], ...) : object 'column' not found.
请问该怎么修正呢,谢谢各位啦。