楼主: 苏谷壳
1625 4

[问答] 请问ggmap包里面的hadley图是怎么做出来的 [推广有奖]

  • 1关注
  • 0粉丝

本科生

70%

还不是VIP/贵宾

-

威望
0
论坛币
23 个
通用积分
3.2667
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1151 点
帖子
63
精华
0
在线时间
85 小时
注册时间
2016-1-3
最后登录
2021-6-29

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

加载ggmap包后,执行

  1. library(ggmap)
  2. ggimage(hadley)
复制代码

会出现一张Hadley的图像,这张图像尝试自己做一下,但是尝试了很多再次都失败了
效果图原始图片见附件

  1. library(EBImage)
  2. library(ggplot2)
  3. library(reshape)
  4. image <- readImage('Hadley.jpg')
  5. theme_set(theme_bw())
  6. gimage <- function(image){
  7.   require(ggplot2)
  8.   # remove first pound for the image in the case study
  9.   if(length(dim(image)) == 2){
  10.     message('creating black and white image...')
  11.     image <- melt(image)
  12.     names(image) <- c('row','column','fill')
  13.     plot <- qplot(column, -row, data = image, geom = 'tile', fill = fill) +
  14.       scale_fill_gradient(low = 'black', high = 'white')
  15.   }
  16. if(length(dim(image)) == 3){
  17.    message('creating color image...')
  18.    image <- apply(image,1:2,function(v)rgb(v[1],v[2],v[3]))
  19.    image <- melt(image)
  20.    plot <- ggplot(image, aes(row, -column, fill=fill)) + geom_tile() + scale_fill_identity()        
  21. }
  22.   plot +
  23.     theme(      
  24.       axis.line = element_line(), axis.ticks = element_line(),
  25.       axis.text.x = element_text(), axis.text.y = element_text(),
  26.       axis.title.x = element_text(), axis.title.y = element_text(),
  27.       axis.ticks.length = unit(0, "lines"),
  28.       axis.ticks.margin = unit(0, "lines"),
  29.       legend.position = "none",
  30.       panel.background = element_rect(),
  31.       panel.border = element_rect(),
  32.       panel.grid.major = element_line(),
  33.       panel.grid.minor = element_line(),
  34.       panel.margin = unit(0, "lines"),
  35.       plot.background = element_rect(),
  36.       plot.title = element_text(),
  37.       plot.margin = unit(c(-1, -1, -1.5, -1.5), "lines")
  38.     )
  39. }
  40. 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.
请问该怎么修正呢,谢谢各位啦。


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:image READ DIM ima Age

Rplot.png (85.85 KB)

效果图

效果图

Hadley.jpg (9.78 KB)

原始图片

原始图片

沙发
苏谷壳 发表于 2017-8-20 14:48:42 |只看作者 |坛友微信交流群
搞不懂了

使用道具

藤椅
苏谷壳 发表于 2017-8-21 10:08:51 |只看作者 |坛友微信交流群
请大家给点意见吧

使用道具

板凳
苏谷壳 发表于 2017-8-22 22:31:40 |只看作者 |坛友微信交流群
好难呢

使用道具

报纸
zhou1_20 发表于 2019-3-26 10:28:10 |只看作者 |坛友微信交流群
  1. colnames(image)=c('row','column','fill')
复制代码

第二个if少这个

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-25 09:10