Image 设置将数据叠加到R中图像上的参考点
我在这里看到了一些关于使用R绘制图像的问题(我甚至提出了一个) 这里的区别是,我需要为我的图像设置参考坐标,以匹配我要在图像顶部绘制的数据 更具体地说,我需要R来理解背景图像的坐标是Image 设置将数据叠加到R中图像上的参考点,image,r,Image,R,我在这里看到了一些关于使用R绘制图像的问题(我甚至提出了一个) 这里的区别是,我需要为我的图像设置参考坐标,以匹配我要在图像顶部绘制的数据 更具体地说,我需要R来理解背景图像的坐标是x=(-100100)和y=(40,-40) 我已经能够读取图像文件并使用ReadImages软件包进行打印,但是当我使用points()覆盖数据时,数据显然没有正确对齐 非常感谢您的帮助 编辑:以下是一些示例数据,我附上了图片: structure(list(teamid = c("6", "6", "6", "6
x=(-100100)
和y=(40,-40)
我已经能够读取图像文件并使用ReadImages
软件包进行打印,但是当我使用points()
覆盖数据时,数据显然没有正确对齐
非常感谢您的帮助
编辑:以下是一些示例数据,我附上了图片:
structure(list(teamid = c("6", "6", "6", "6", "6", "6", "2",
"6", "6", "6", "2", "6", "10", "10", "10", "10", "20", "20",
"10", "10", "10", "20", "20", "20", "10", "10"), xcoord = c("79",
"81", "33", "34", "75", "52", "-67", "80", "44", "79", "-53",
"54", "-55", "-81", "-66", "-66", "45", "81", "-78", "-70", "-59",
"50", "53", "63", "-79", "-78"), ycoord = c("0", "0", "-18",
"-20", "6", "-11", "-7", "7", "-28", "-10", "35", "22", "25",
"-5", "25", "23", "-11", "13", "22", "16", "13", "23", "7", "16",
"8", "8")), .Names = c("teamid", "xcoord", "ycoord"), class = "data.frame", row.names = c(74328L,
74331L, 74332L, 74334L, 74336L, 74338L, 74340L, 74341L, 74346L,
74347L, 74348L, 74349L, 100136L, 100137L, 100138L, 100139L, 100147L,
100148L, 100151L, 100154L, 100156L, 100158L, 100159L, 100161L,
100163L, 100167L))
您可以创建具有正确尺寸的空打印,然后使用
光栅图像
功能打印图像,然后添加点应该可以正常工作
另一种方法是在绘制图像后使用TeachingDemos
软件包中的updateusr
函数,以确保坐标与添加线或点之前所需的坐标匹配
我将上面的图形保存为ice.png,并运行以下代码:
library(EBImage)
ice <- readImage('My Pictures/ice.png')
pos <- structure(list(teamid = c("6", "6", "6", "6", "6", "6", "2",
"6", "6", "6", "2", "6", "10", "10", "10", "10", "20", "20",
"10", "10", "10", "20", "20", "20", "10", "10"), xcoord = c("79",
"81", "33", "34", "75", "52", "-67", "80", "44", "79", "-53",
"54", "-55", "-81", "-66", "-66", "45", "81", "-78", "-70", "-59",
"50", "53", "63", "-79", "-78"), ycoord = c("0", "0", "-18",
"-20", "6", "-11", "-7", "7", "-28", "-10", "35", "22", "25",
"-5", "25", "23", "-11", "13", "22", "16", "13", "23", "7", "16",
"8", "8")), .Names = c("teamid", "xcoord", "ycoord"),
class = "data.frame", row.names = c(74328L,
74331L, 74332L, 74334L, 74336L, 74338L, 74340L, 74341L, 74346L,
74347L, 74348L, 74349L, 100136L, 100137L, 100138L, 100139L, 100147L,
100148L, 100151L, 100154L, 100156L, 100158L, 100159L, 100161L,
100163L, 100167L))
pos$xcoord <- as.numeric(pos$xcoord)
pos$ycoord <- as.numeric(pos$ycoord)
ice2 <- as.raster(ice)
pin <- par('pin')
plot( c(-100,100), c(-40,40), type='n', xlab='', ylab='',
asp=pin[1]/pin[2], axes=FALSE, xaxs='i', yaxs='i')
rasterImage(ice2, -100, -40, 100, 40, interpolate=FALSE)
with(pos, text(xcoord, ycoord, teamid, col='green', cex=1.2) )
库(EBImage)
你能举个例子说明你做了什么,它看起来像什么,以及你真正想要实现什么。我不明白。你当然可以用光栅图像
工具设置图像坐标,但我怀疑有一种更简单的方法来定位绘图的“背景图像”。我去四处看看。这不是光栅图像所做的吗?看看它在特定坐标处放置图像的例子。好吧,现在你的问题很清楚了:你把Bruins标志忘在了冰中心!我不知道光栅图像,通过您的代码示例,我能够让它工作。非常感谢!