- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试绘制几个国家并根据特定变量用颜色填充它们,并且我已经为一个国家实现了它,但是当我尝试将县相乘时我不断收到错误:向连续比例提供离散值虽然代码基本相同,但这里是非工作代码及其数据集
library(ggplot2)
library(maptools)
library(rgeos)
library(rgdal)
library(gpclib)
library(dplyr)
mne <- get(load('/Users/praeconium/Desktop/Dev/NonResponse/GoliOtok/Paper/Shapes/MNE_adm0.RData'))
sr <- get(load('/Users/praeconium/Desktop/Dev/NonResponse/GoliOtok/Paper/Shapes/SRB_adm0.RData'))
sl <- get(load('/Users/praeconium/Desktop/Dev/NonResponse/GoliOtok/Paper/Shapes/SVN_adm0.RData'))
hr <- get(load('/Users/praeconium/Desktop/Dev/NonResponse/GoliOtok/Paper/Shapes/HRV_adm0.RData'))
bh <- get(load('/Users/praeconium/Desktop/Dev/NonResponse/GoliOtok/Paper/Shapes/BIH_adm0.RData'))
mk <- get(load('/Users/praeconium/Desktop/Dev/NonResponse/GoliOtok/Paper/Shapes/MKD_adm0.RData'))
gpclibPermit()
mne.adm0.df <- fortify(mne, region = "NAME_ENGLISH")
sr.adm0.df <- fortify(sr, region = "NAME_ENGLISH")
sl.adm0.df <- fortify(sl, region = "NAME_ENGLISH")
hr.adm0.df <- fortify(hr, region = "NAME_ENGLISH")
bh.adm0.df <- fortify(bh, region = "NAME_ENGLISH")
mk.adm0.df <- fortify(mk, region = "NAME_ENGLISH")
combine <- 0
combine <- rbind(combine, mne.adm0.df)
combine1 <- rbind(combine, sr.adm0.df)
combine2 <- rbind(combine1, sl.adm0.df)
combine3 <- rbind(combine2, hr.adm0.df)
combine4 <- rbind(combine3, bh.adm0.df)
combine5 <- rbind(combine4, mk.adm0.df)
rm(combine,combine1,combine2,combine3, combine4)
combine6 <- combine5[-1,]
States <- data.frame(id=unique(combine6$id), emp=c(1,2,3,1,2,3), long=c("19.09462","19.70397","16.28719","16.40274","16.96187","22.23574"), lat=c("43.52889","46.18837","46.8704","46.43516","45.22893","42.3041"))
Set <- merge(combine6, States, by='id')
p <- ggplot(Set, aes(x = lat.x, y = long.x, group = group)) +
geom_polygon(aes(fill = cut(emp,10))) +
geom_text(data = States, aes(label = id, x = long, y = lat, group = id), size = 3) +
labs(x=" ", y=" ") +
theme_bw() + scale_fill_brewer('Rate', palette = 'PuRd') +
coord_map() +
theme(panel.grid.minor=element_blank(), panel.grid.major=element_blank()) +
theme(axis.ticks = element_blank(), axis.text.x = element_blank(), axis.text.y = element_blank()) +
theme(panel.border = element_blank())
print(p)
session 输出和数据集
> str(Set)
'data.frame': 220148 obs. of 10 variables:
$ id : chr "Bosnia and Herzegovina" "Bosnia and Herzegovina" "Bosnia and Herzegovina" "Bosnia and Herzegovina" ...
$ long.x: num 16.9 16.9 16.9 16.9 17 ...
$ lat.x : num 45.2 45.2 45.2 45.2 45.2 ...
$ order : num 1 2 3 4 5 6 7 8 9 10 ...
$ hole : num 0 0 0 0 0 0 0 0 0 0 ...
$ piece : Factor w/ 521 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ...
$ group : Factor w/ 531 levels "Montenegro.1",..: 530 530 530 530 530 530 530 530 530 530 ...
$ emp : num 2 2 2 2 2 2 2 2 2 2 ...
$ long.y: Factor w/ 6 levels "16.28719","16.40274",..: 3 3 3 3 3 3 3 3 3 3 ...
$ lat.y : Factor w/ 6 levels "42.3041","43.52889",..: 3 3 3 3 3 3 3 3 3 3 ...
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] psych_1.3.2 gridExtra_0.9.1 lubridate_1.3.3 mapproj_1.2-1 maps_2.3-6 dplyr_0.1 gpclib_1.5-5 rgdal_0.8-16
[9] rgeos_0.3-4 maptools_0.8-29 sp_1.0-14 ggplot2_0.9.3.1
loaded via a namespace (and not attached):
[1] assertthat_0.1 colorspace_1.2-2 dichromat_2.0-0 digest_0.6.3 foreign_0.8-55 gtable_0.1.2
[7] labeling_0.2 lattice_0.20-23 MASS_7.3-29 memoise_0.1 munsell_0.4.2 plyr_1.8
[13] proto_0.3-10 RColorBrewer_1.0-5 Rcpp_0.11.0 reshape2_1.2.2 scales_0.2.3 stringr_0.6.2
[19] tools_3.0.2
> headTail(Set)
id long.x lat.x order hole piece group emp long.y lat.y
1 Bosnia and Herzegovina 16.93 45.23 1 0 1 Bosnia and Herzegovina.1 2 16.96187 45.22893
2 Bosnia and Herzegovina 16.94 45.23 2 0 1 Bosnia and Herzegovina.1 2 16.96187 45.22893
3 Bosnia and Herzegovina 16.95 45.23 3 0 1 Bosnia and Herzegovina.1 2 16.96187 45.22893
4 Bosnia and Herzegovina 16.95 45.23 4 0 1 Bosnia and Herzegovina.1 2 16.96187 45.22893
... <NA> ... ... ... ... <NA> <NA> ... <NA> <NA>
220145 Slovenia 13.6 45.49 2791 0 2 Slovenia.2 3 16.28719 46.8704
220146 Slovenia 13.6 45.49 2792 0 2 Slovenia.2 3 16.28719 46.8704
220147 Slovenia 13.6 45.5 2793 0 2 Slovenia.2 3 16.28719 46.8704
220148 Slovenia 13.6 45.5 2794 0 2 Slovenia.2 3 16.28719 46.8704
这是工作代码及其输出,基本相同,只是文件在不同的管理级别
library(ggplot2)
library(maptools)
library(rgeos)
library(rgdal)
library(gpclib)
load("/Users/praeconium/Downloads/MNE_adm1.RData")
mne.adm2.spdf <- get("gadm")
gpclibPermit()
mne.adm2.df <- fortify(mne.adm2.spdf, region = "NAME_1")
id <- unique(mne.adm2.df$id)
emp <- c(1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3)
unemp <- data.frame(id,emp)
mne2 <- merge(mne.adm2.df, unemp, by='id')
mne.centro <- data.frame(long = coordinates(mne.adm2.spdf)[, 1], lat = coordinates(mne.adm2.spdf)[, 2])
towns <- c("And", "Bar", "Berane", "BP", "BD", "CT", "DG", "HN", "KOl", "KO", "MK", "NK", "PL", "PV", "PLu", "PG", "RO", "SA", "TV", "UL", "ZB")
id <- unique(mne.adm2.df$id)
mne.centro3 <- data.frame(towns, mne.centro, id)
# Plot
p <- ggplot(mne2, aes(x = long, y = lat, group = group)) +
geom_polygon(aes(fill = cut(emp,5))) +
geom_text(data = mne.centro3, aes(label = towns, x = long, y = lat, group = towns), size = 3) +
labs(x=" ", y=" ") +
theme_bw() + scale_fill_brewer('Rate', palette = 'PuRd') +
coord_map() +
theme(panel.grid.minor=element_blank(), panel.grid.major=element_blank()) +
theme(axis.ticks = element_blank(), axis.text.x = element_blank(), axis.text.y = element_blank()) +
theme(panel.border = element_blank())
print(p)
> str(mne2)
data.frame': 12931 obs. of 8 variables:
$ id : chr "Andrijevica" "Andrijevica" "Andrijevica" "Andrijevica" ...
$ long : num 19.9 19.9 19.9 19.8 19.8 ...
$ lat : num 42.7 42.7 42.7 42.7 42.7 ...
$ order: int 1 2 3 4 5 6 7 8 9 10 ...
$ hole : logi FALSE FALSE FALSE FALSE FALSE FALSE ...
$ piece: Factor w/ 4 levels "1","2","3","4": 1 1 1 1 1 1 1 1 1 1 ...
$ group: Factor w/ 27 levels "Andrijevica.1",..: 1 1 1 1 1 1 1 1 1 1 ...
$ emp : num 1 1 1 1 1 1 1 1 1 1 ...
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] grid stats graphics grDevices utils
[6] datasets methods base
other attached packages:
[1] psych_1.3.2 gridExtra_0.9.1 lubridate_1.3.3
[4] mapproj_1.2-1 maps_2.3-6 dplyr_0.1
[7] gpclib_1.5-5 rgdal_0.8-16 rgeos_0.3-4
[10] maptools_0.8-29 sp_1.0-14 ggplot2_0.9.3.1
loaded via a namespace (and not attached):
[1] assertthat_0.1 colorspace_1.2-2
[3] dichromat_2.0-0 digest_0.6.3
[5] foreign_0.8-55 gtable_0.1.2
[7] labeling_0.2 lattice_0.20-23
[9] MASS_7.3-29 memoise_0.1
[11] munsell_0.4.2 plyr_1.8
[13] proto_0.3-10 RColorBrewer_1.0-5
[15] Rcpp_0.11.0 reshape2_1.2.2
[17] scales_0.2.3 stringr_0.6.2
[19] tools_3.0.2
> headTail(mne2)
id long lat order hole piece group emp
1 Andrijevica 19.89 42.68 1 FALSE 1 Andrijevica.1 1
2 Andrijevica 19.88 42.67 2 FALSE 1 Andrijevica.1 1
3 Andrijevica 19.85 42.66 3 FALSE 1 Andrijevica.1 1
4 Andrijevica 19.84 42.66 4 FALSE 1 Andrijevica.1 1
... <NA> ... ... ... <NA> <NA> <NA> ...
12928 Žabljak 19.02 43.25 12928 FALSE 1 Žabljak.1 3
12929 Žabljak 19.02 43.26 12929 FALSE 1 Žabljak.1 3
12930 Žabljak 19.03 43.26 12930 FALSE 1 Žabljak.1 3
12931 Žabljak 19.03 43.26 12931 FALSE 1 Žabljak.1 3
为了解决这些问题,我已经遵循这些问题,但我仍然不明白我做错了什么? Administrative regions map of a country with ggmap and ggplot2我检查了这些和这些 Specifying the colour scale for maps in ggplot Add color to boxplot - "Continuous value supplied to discrete scale" error
最佳答案
我通过排除部分解决了目标但不是手头的任务
geom_text(data = mne.centro3, aes(label = towns, x = long, y = lat, group = towns), size = 3) +
但我不明白为什么相同的代码在这里是连续的而在那里是离散的:S
关于r - ggplot2 多边形 -> 错误 : Discrete value supplied to continuous scale,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23046963/
我已经实现了 Bentley-Ottmann-algorithm检测多边形-多边形交叉点。这通常非常有效:由于多边形不自相交,因此两个多边形的线段并集中的任何线段相交表明两个多边形相交。 但是如果我看
我在 Silverlight 中有一个多边形(棋盘游戏的十六进制),例如; public class GridHex : IGridShape { ..... public IList
我创建了一个简单的 DirectX 应用程序来渲染一个顶点场。顶点呈现如下(如果从顶部查看): |\|\|\|\| |\|\|\|\| 每个三角形都是这样渲染的: 1 |\ 2 3 这应该意味着多边形
我的代码的某些部分here : var stage = new Kinetic.Stage({ container: "canvas", width: 300,
我正在尝试从 map 数据构造导航网格物体。步骤之一涉及将二进制图像(其中0表示占用空间,1表示自由空间)转换成平面直线图。 我正在尝试找到一种可靠的方法。我目前的想法是使用Canny边缘检测器,然后
我的任务是编写 MATLAB 代码来生成一个由 4 部分组成的 Logo ,如屏幕截图所示。左上角应为黑色,右下角应为白色。另一个程序应随机选择两种颜色。 我采取了以下方法: clear all cl
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
如何向 google.maps.Rectangle 和 google.maps.Polygon 添加标题? title 属性在 RectangleOptions 中不可用.我试过了,但没用(对于 go
我有一个表,用于将表上的段存储为多边形。然后我想获取所有被另一个多边形接触的线段,例如正方形或圆形。图片上:http://img.acianetmedia.com/GJ3 我将灰色小框表示为段和 bi
我正在我的网站上使用 CSS 来制作形状。它在 chrome 中运行良好,但在 mozilla、internet explorer 中打开时,它无法运行。 有人知道怎么解决吗? 这是 fiddle h
我使用 DrawingManager 在 Google map 上绘制圆形和多边形。我尝试使用下面的代码删除圆形/多边形。 selectedShape.setMap(null); 这里selected
我看到了很多如何检测碰撞的教程,但没有看到如何解决它。我正在制作一个自上而下的游戏,玩家具有圆形碰撞形状,而墙壁是各种多边形。 我正在使用 slick2d。我应该做的是,如果玩家与角落碰撞,我会按法线
我对 tkinter 比较陌生,我正在制作一个只使用正方形的游戏。我正在抄写的书只显示三角形。这是代码: # The tkinter launcher (Already complete) from
我在 OpenCV/Python 中工作,我遇到了这个问题。我已经使用 cv2.minAreaRect() 来获取围绕一组点的边界框。是否有任何其他函数/通用算法可以给我内接多边形(点集)的最大矩形?
如果给定一组线段 S ,我们能否设计一种算法来测试集合 S 中的线段是否可以形成多边形,我对它们是否相交多边形不感兴趣,我只想知道我可以测试什么标准, 任何建议 最佳答案 构建一个图形数据结构,其中节
如何从多个地理位置(经度、纬度值)创建多边形地理围栏。此外,如何在 Android 上跟踪用户进入此地理围栏区域或从该区域退出。 最佳答案 地理围栏只是一组形成多边形的纬度/经度点。获得纬度/经度点列
我想要一个 complex image like this在我的申请中。我想让用户点击复杂的多边形(在这种情况下是有边界的国家/地区)并突出显示他们点击的多边形。我有我需要用于该状态的图像。 我怎样才
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
我想在 python tkinter 中移动对象,特别是多边形。问题出在 is_click 函数中。我似乎无法弄清楚如何确定我是否单击了该对象。代码还没有 100% 完成,移动仍然需要完成,但我现在需
我有一个大多边形,我想找到与该多边形相交的要素,但由于多边形太大,我遇到超时异常。 我试图研究 JTS 方法,但不知道如何使用它。 final List coordinates = List.of(n
我是一名优秀的程序员,十分优秀!