R ggplot2映射:Don';I don’我不知道如何自动选择秤
我正试着在选区地图上标出地址。我的程序使用以下库:R ggplot2映射:Don';I don’我不知道如何自动选择秤,r,ggplot2,maps,R,Ggplot2,Maps,我正试着在选区地图上标出地址。我的程序使用以下库: # load libraries library(ggplot2) library(maptools) library(mapproj) library(plyr) library(sp) library(rgdal) library(rgeos) library(ggmap) 相关代码如下: #Generating Map #f.dist_1 contains longitude, latitude and a group id ident
# load libraries
library(ggplot2)
library(maptools)
library(mapproj)
library(plyr)
library(sp)
library(rgdal)
library(rgeos)
library(ggmap)
相关代码如下:
#Generating Map
#f.dist_1 contains longitude, latitude and a group id identifting precincts
distMap <- ggplot(data = f.dist_1, aes(x=longitude, y=latitude, group = id))
#Create map file and precinct outlines
distMap <- distMap + geom_polygon(fill="aliceblue")
distMap <- distMap + geom_path(color= "black",aes(group=group))
#f.canvassu2 contains household data, longitude ("lon") and latitude ("lat") value
#Plot selected households; this statement throws the error:
#生成地图
#f、 dist_1包含经度、纬度和识别选区的组id
distMap使用此选项
# using aesthetic to just load data to map
distMap <- distMap + aes(x=as.numeric(f.canvassu2$lon), y=as.numeric(f.canvassu2$lon)) + geom_point(size=2)
# just check if map is displayed
distMap
#使用美学将数据加载到地图
distMap如果您是一名软件包开发人员,来到这里是因为您的新类引发了此错误,您可以通过在ggplot2
中“添加”一个函数来修复此错误:
x <- letters[1:10]
class(x) <- "my_great_class" # here starts the problem
y <- runif(10)
ggplot(data.frame(x = x, y = y), aes(x = x, y = y)) +
geom_col()
#> Don't know how to automatically pick scale for object of type my_great_class. Defaulting to continuous.
#> Error: Discrete value supplied to continuous scale
# ------ ADD THIS TO YOUR PACKAGE ------
#' @exportMethod scale_type.my_great_class
#' @export
#' @noRd
scale_type.my_great_class <- function(x) {
"discrete"
}
# ------------- UNTIL HERE -------------
# now works:
ggplot(data.frame(x = x, y = y), aes(x = x, y = y)) +
geom_col()
x欢迎来到SO.)目前,由于您没有提供任何具体数据,很难看到您正在尝试做什么。如果您想从SO用户那里获得一些支持,您需要发布可复制的代码和示例。你能考虑修改一下你的问题吗?同时,我认为您的f.dist_1
似乎是一个空间聚合数据帧。如果没有,则已使用fortify
将其包含在data.frame中。不过我只是在猜测。请更新您的问题。:)dput(head(f.canvassu2))
和dput(head(f.dist_1))
真的很有帮助
x <- letters[1:10]
class(x) <- "my_great_class" # here starts the problem
y <- runif(10)
ggplot(data.frame(x = x, y = y), aes(x = x, y = y)) +
geom_col()
#> Don't know how to automatically pick scale for object of type my_great_class. Defaulting to continuous.
#> Error: Discrete value supplied to continuous scale
# ------ ADD THIS TO YOUR PACKAGE ------
#' @exportMethod scale_type.my_great_class
#' @export
#' @noRd
scale_type.my_great_class <- function(x) {
"discrete"
}
# ------------- UNTIL HERE -------------
# now works:
ggplot(data.frame(x = x, y = y), aes(x = x, y = y)) +
geom_col()