从R中的(x,y)关联创建热图 [英] Creating a heat map from (x,y) corrdinates in R

查看:88
本文介绍了从R中的(x,y)关联创建热图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将其制作成热图的文本文件(data.csv)中包含(x,y)数据.

I have (x,y) data in a text file (data.csv) I would like to make into a heat map.

X   Y
-60 -18
60  -62
7   14
-22 -60
59  58
29  22
-58 -18
60  -61
7   14
-21 -59
61  59
29  22
-57 -18
-22 -59
59  60
29  24
-56 -17
61  -60
8   16
-20 -58
62  60
30  23

理想情况下,我希望能够导入文本文件并将其保存到450px x 200px的图像文件(PNG或JPG)中.

Ideally I would like to be able to import the text file and save it to a image file (PNG or JPG) that is 450px x 200px.

热图需要更像您在Google Maps上找到的(此处的示例),而不是矩阵(

The heat map needs to be more like one you'd find on Google Maps (example here) than a matrix (example here).

谢谢.

推荐答案

如果您正在查看密度图,其中颜色表示平面中点的分布,则可以使用例如kde2d函数从MASS库中紧随其后,然后是filled.contour.

If you are looking at a density plot, where the color represents distribution of the points in the plane, you can use, for example, the kde2d function from the MASS library followed by filled.contour.

可复制的示例:

d <- structure(list(X = c(-60L, 60L, 7L, -22L, 59L, 29L, -58L, 60L, 
7L, -21L, 61L, 29L, -57L, -22L, 59L, 29L, -56L, 61L, 8L, -20L, 
62L, 30L), Y = c(-18L, -62L, 14L, -60L, 58L, 22L, -18L, -61L, 
14L, -59L, 59L, 22L, -18L, -59L, 60L, 24L, -17L, -60L, 16L, -58L, 
60L, 23L)), .Names = c("X", "Y"), class = "data.frame", row.names = c(NA, 
-22L))
require(MASS)
dens <- kde2d(d$X, d$Y, h=75, n=50)  #overrode default bandwidth
filled.contour(dens)

有许多其他功能可以根据给定的密度绘制图.

There are lots of other functions that will make you a plot given the density.

这篇关于从R中的(x,y)关联创建热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆