- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想绘制一个热图,但有数量,而不是我在教程 (here) 中看到的单一输入。我也看过 this 示例,但它本身并不是热图。您知道如何在热图中整合每个位置的数量吗?我不知道应该把它放在哪里。
我的代码是:
#Get the Massachusetts map
ma_map <- get_map(location = "Massachusetts", maptype = "terrain", zoom = 8)
#Create the map with the companies
ggmap(ma_map, extent = "device") + geom_point(aes(x = lon, y = lat), size = (heatdata$Quantity),
colour = "red", alpha = 0.5, data = heatdata)
#Create heat map
ggmap(ma_map, extent = "device") + geom_density2d(data = heatdata,
aes(x = lon, y = lat), size = 0.3) + stat_density2d(data = heatdata,
aes(x = lon, y = lat, fill = ..level.., alpha = ..level..), size = 0.01,
bins = 16, geom = "polygon") + scale_fill_gradient(low = "green", high = "red")
+ scale_alpha(range = c(0, 0.3), guide = FALSE)
我的数据集是:
structure(list(Quantity = c(1L, 3L, 2L, 1L, 2L, 1L, 3L, 11L,
1L, 1L, 6L, 2L, 2L, 1L, 1L, 1L, 2L, 9L, 7L, 1L, 1L, 6L, 1L, 1L,
3L, 1L, 2L, 3L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 3L,
4L, 1L, 1L, 3L, 2L, 1L, 2L, 3L, 3L, 6L, 1L, 3L, 1L, 8L, 1L, 1L,
2L, 2L, 1L, 4L, 1L, 1L, 2L, 3L, 1L, 1L, 3L, 1L, 1L, 1L, 2L, 4L,
1L, 5L, 1L, 5L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 7L, 1L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 5L, 1L, 1L, 2L, 1L, 1L,
1L, 1L, 2L, 2L, 3L, 1L, 1L, 5L, 16L, 2L), lon = c(-72.6148117,
-71.1367953, -71.1564729, -71.4633956, -71.8356271, -71.2471097,
-71.5899054, -71.2760089, -71.4745881, -70.880049, -71.2689461,
-71.0588801, -71.5167139, -71.0758905, -70.9750541, -71.0183787,
-71.1211635, -71.1956205, -71.1097335, -71.1447732, -71.970074,
-71.3672838, -71.166187, -72.6078672, -71.6829081, -70.8036544,
-71.3489484, -70.932122, -71.1676536, -71.615556, -72.5125863,
-71.1550451, -71.8022955, -71.396725, -71.998133, -70.6619888,
-73.362008, -72.5884222, -70.9744964, -70.889759, -71.4245049,
-72.6162009, -71.5411747, -71.5225646, -71.566139, -70.2881124,
-71.1631137, -71.2289641, -71.5128022, -71.3161718, -71.066163,
-71.2190578, -70.8578024, -71.5522874, -71.4495058, -71.3967256,
-71.1908924, -71.5163049, -71.761522, -71.35, -71.2377548, -70.934205,
-70.8772751, -71.2092214, -71.2205981, -71.3250563, -71.1350575,
-71.2845035, -71.383617, -71.6969985, -71.1869963, -71.1989695,
-71.8647577, -70.9286609, -70.8092, -73.2453824, -70.6672621,
-70.616142, -71.042551, -70.9161551, -70.8967155, -71.6495176,
-71.7128471, -72.7300929, -71.5245087, -72.0333905, -72.589811,
-71.7606293, -71.0999719, -71.102778, -72.0787059, -70.9175562,
-71.2342248, -72.3356375, -70.9495053, -71.4244224, -71.0723391,
-71.2495096, -71.2356113, -71.1036688, -70.7197342, -71.2923877,
-71.1359393, -71.2250533, -72.6203675, -70.7603143, -71.6161294,
-72.749538, -71.4378411, -71.2244987, -71.6661783, -71.1724467,
-71.1522765, -71.8022934), lat = c(42.0695391, 42.6583356, 42.4153925,
42.2612067, 42.1945385, 42.3479782, 42.5611947, 42.4906231, 42.0867608,
42.5584283, 42.5584218, 42.3600825, 42.4834197, 42.7695348, 41.9903519,
42.0834335, 42.3317642, 42.5047161, 42.3736158, 42.1584324, 42.13565,
42.5998139, 42.3303798, 42.1487043, 42.4167635, 42.2417675, 42.4603719,
42.5750009, 42.2436085, 42.537222, 42.0645396, 41.7014912, 42.5834228,
42.0834313, 42.5750883, 42.6159285, 42.1959798, 42.3417565, 42.5862053,
42.2418172, 42.2000966, 42.2042586, 42.1306522, 42.2286954, 42.391736,
41.6524911, 42.7070354, 42.4430372, 42.5372893, 42.6334247, 42.4250964,
42.0334565, 42.4999582, 42.3459271, 42.4334903, 42.1417641, 42.7262016,
42.1398577, 42.1920719, 42.283333, 42.2809285, 41.6362152, 42.8125913,
42.3370413, 42.3121798, 42.1195426, 42.6987024, 42.5834258, 42.6396055,
42.2356407, 41.9667703, 42.1943909, 42.1167606, 42.5278731, 42.0714925,
42.4500845, 41.9584457, 41.6862173, 42.1619739, 42.1306563, 42.51954,
42.5437035, 42.2959267, 42.2292572, 42.3056501, 42.0751065, 42.1014831,
42.4374156, 42.4802469, 42.125, 42.1084122, 42.4709437, 42.6106478,
42.1875933, 42.6375941, 42.6766696, 42.5039395, 42.1417442, 42.3764852,
42.7567572, 41.7614511, 42.296797, 42.4249311, 42.3497948, 42.1070383,
41.7898254, 42.2695216, 42.1250929, 42.5792583, 42.2139873, 42.1112075,
42.5481714, 42.4792618, 42.2625932)), .Names = c("Quantity",
"lon", "lat"), row.names = c(NA, -114L), class = "data.frame")
最佳答案
不确定是否有办法传递数量?也许只是创建一个重复以下要点的新数据框:
library(plyr)
temp <- apply(heatdata, 1, function(x) { data.frame(lon = rep(x[2], x[1]),
lat = rep(x[3], x[1]))})
heatdata2 <- ldply(temp, rbind)
ggmap(ma_map, extent="device") +
stat_density2d(data=heatdata2, aes(x=lon, y=lat, fill=..level..,
alpha=..level..),
geom="polygon", size=0.01, bins=16) +
scale_fill_gradient(low="green", high="red") +
scale_alpha(range = c(0, 0.3), guide=FALSE)
关于r - ggmap R 中带有数量的热图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28905089/
我正在从 Stata 迁移到 R(plm 包),以便进行面板模型计量经济学。在 Stata 中,面板模型(例如随机效应)通常报告组内、组间和整体 R 平方。 I have found plm 随机效应
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 6年前关闭。 Improve this qu
我想要求用户输入整数值列表。用户可以输入单个值或一组多个值,如 1 2 3(spcae 或逗号分隔)然后使用输入的数据进行进一步计算。 我正在使用下面的代码 EXP <- as.integer(rea
当 R 使用分类变量执行回归时,它实际上是虚拟编码。也就是说,省略了一个级别作为基础或引用,并且回归公式包括所有其他级别的虚拟变量。但是,R 选择了哪一个作为引用,以及我如何影响这个选择? 具有四个级
这个问题基本上是我之前问过的问题的延伸:How to only print (adjusted) R-squared of regression model? 我想建立一个线性回归模型来预测具有 15
我在一台安装了多个软件包的 Linux 计算机上安装了 R。现在我正在另一台 Linux 计算机上设置 R。从他们的存储库安装 R 很容易,但我将不得不使用 安装许多包 install.package
我正在阅读 Hadley 的高级 R 编程,当它讨论字符的内存大小时,它说: R has a global string pool. This means that each unique strin
我们可以将 Shiny 代码写在两个单独的文件中,"ui.R"和 "server.R" , 或者我们可以将两个模块写入一个文件 "app.R"并调用函数shinyApp() 这两种方法中的任何一种在性
我正在使用 R 通过 RGP 包进行遗传编程。环境创造了解决问题的功能。我想将这些函数保存在它们自己的 .R 源文件中。我这辈子都想不通怎么办。我尝试过的一种方法是: bf_str = print(b
假设我创建了一个函数“function.r”,在编辑该函数后我必须通过 source('function.r') 重新加载到我的全局环境中。无论如何,每次我进行编辑时,我是否可以避免将其重新加载到我的
例如,test.R 是一个单行文件: $ cat test.R # print('Hello, world!') 我们可以通过Rscript test.R 或R CMD BATCH test.R 来
我知道我可以使用 Rmd 来构建包插图,但想知道是否可以更具体地使用 R Notebooks 来制作包插图。如果是这样,我需要将 R Notebooks 编写为包小插图有什么不同吗?我正在使用最新版本
我正在考虑使用 R 包的共享库进行 R 的站点安装。 多台计算机将访问该库,以便每个人共享相同的设置。 问题是我注意到有时您无法更新包,因为另一个 R 实例正在锁定库。我不能要求每个人都关闭它的 R
我知道如何从命令行启动 R 并执行表达式(例如, R -e 'print("hello")' )或从文件中获取输入(例如, R -f filename.r )。但是,在这两种情况下,R 都会运行文件中
我正在尝试使我当前的项目可重现,因此我正在创建一个主文档(最终是一个 .rmd 文件),用于调用和执行其他几个文档。这样我自己和其他调查员只需要打开和运行一个文件。 当前设置分为三层:主文件、2 个读
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 5年前关闭。 Improve this qu
我的 R 包中有以下描述文件 Package: blah Title: What the Package Does (one line, title case) Version: 0.0.0.9000
有没有办法更有效地编写以下语句?accel 是一个数据框。 accel[[2]]<- accel[[2]]-weighted.mean(accel[[2]]) accel[[3]]<- accel[[
例如,在尝试安装 R 包时 curl作为 usethis 的依赖项: * installing *source* package ‘curl’ ... ** package ‘curl’ succes
我想将一些软件作为一个包共享,但我的一些脚本似乎并不能很自然地作为函数运行。例如,考虑以下代码块,其中“raw.df”是一个包含离散和连续类型变量的数据框。函数“count.unique”和“squa
我是一名优秀的程序员,十分优秀!