I Sincerely thought id found the bug till i scrolled down on their visitor comments to see that misiti- https://disqus.com/by/misiti3780/ , had pointed it out earlier , well here is the post anyways :)
My results are different as i have plotted on - mydata$OT.Number
mydata = read.csv("vehicle-accidents.csv")
mydata$State <- as.character(mydata$State)
mydata$MV.Number = as.numeric(mydata$MV.Number)
mydata = mydata[mydata$State != "Alaska", ]
mydata = mydata[mydata$State != "Hawaii", ]
#
for (i in 1:nrow(mydata)) {
latlon = geocode(mydata[i,1])
mydata$lon[i] = as.numeric(latlon[1])
mydata$lat[i] = as.numeric(latlon[2])
}
#-
mv_num_collisions = data.frame(mydata$OT.Number, mydata$lon, mydata$lat)
# MV Number to OT Number
#
#
colnames(mv_num_collisions) = c('collisions','lon','lat')
#
usa_center = as.numeric(geocode("United States"))
#
USAMap = ggmap(get_googlemap(center=usa_center, scale=2, zoom=4), extent="normal")
str(USAMap)
#
circle_scale_amt=0.75
USAMap +
geom_point(aes(x=lon, y=lat), color="red",data=mv_num_collisions, alpha=0.4,size=mv_num_collisions$collisions*circle_scale_amt) +
scale_size_continuous(range=range(mv_num_collisions$collisions))
List of 9
$ data :'data.frame': 4 obs. of 2 variables:
..$ lon: num [1:4] -123.8 -67.5 -123.8 -67.5
..$ lat: num [1:4] 11.7 11.7 56.1 56.1
..- attr(*, "out.attrs")=List of 2
.. ..$ dim : Named int [1:2] 2 2
.. .. ..- attr(*, "names")= chr [1:2] "lon" "lat"
.. ..$ dimnames:List of 2
.. .. ..$ lon: chr [1:2] "lon=-123.79395" "lon= -67.54395"
.. .. ..$ lat: chr [1:2] "lat=11.73830" "lat=56.09656"
$ layers :List of 3
..$ :Classes 'LayerInstance', 'Layer', 'ggproto' <ggproto object: Class LayerInstance, Layer>
aes_params: list
compute_aesthetics: function
compute_geom_1: function
compute_geom_2: function
compute_position: function
compute_statistic: function
data: waiver
draw_geom: function
geom: <ggproto object: Class GeomBlank, Geom>
aesthetics: function
default_aes: uneval
draw_group: function
draw_key: function
draw_layer: function
draw_panel: function
extra_params: na.rm
handle_na: function
non_missing_aes:
parameters: function
required_aes:
setup_data: function
use_defaults: function
super: <ggproto object: Class Geom>
geom_params: list
inherit.aes: TRUE
map_statistic: function
mapping: NULL
position: <ggproto object: Class PositionIdentity, Position>
compute_layer: function
compute_panel: function
required_aes:
setup_data: function
setup_params: function
super: <ggproto object: Class Position>
print: function
show.legend: NA
stat: <ggproto object: Class StatIdentity, Stat>
compute_group: function
compute_layer: function
compute_panel: function
default_aes: uneval
extra_params: na.rm
non_missing_aes:
parameters: function
required_aes:
retransform: TRUE
setup_data: function
setup_params: function
super: <ggproto object: Class Stat>
stat_params: list
subset: NULL
super: <ggproto object: Class Layer>
..$ :Classes 'LayerInstance', 'Layer', 'ggproto' <ggproto object: Class LayerInstance, Layer>
aes_params: list
compute_aesthetics: function
compute_geom_1: function
compute_geom_2: function
compute_position: function
compute_statistic: function
data: waiver
draw_geom: function
geom: <ggproto object: Class GeomRasterAnn, Geom>
aesthetics: function
default_aes: uneval
draw_group: function
draw_key: function
draw_layer: function
draw_panel: function
extra_params:
handle_na: function
non_missing_aes:
parameters: function
required_aes:
setup_data: function
use_defaults: function
super: <ggproto object: Class Geom>
geom_params: list
inherit.aes: TRUE
map_statistic: function
mapping: NULL
position: <ggproto object: Class PositionIdentity, Position>
compute_layer: function
compute_panel: function
required_aes:
setup_data: function
setup_params: function
super: <ggproto object: Class Position>
print: function
show.legend: NA
stat: <ggproto object: Class StatIdentity, Stat>
compute_group: function
compute_layer: function
compute_panel: function
default_aes: uneval
extra_params: na.rm
non_missing_aes:
parameters: function
required_aes:
retransform: TRUE
setup_data: function
setup_params: function
super: <ggproto object: Class Stat>
stat_params: list
subset: NULL
super: <ggproto object: Class Layer>
..$ :Classes 'LayerInstance', 'Layer', 'ggproto' <ggproto object: Class LayerInstance, Layer>
aes_params: list
compute_aesthetics: function
compute_geom_1: function
compute_geom_2: function
compute_position: function
compute_statistic: function
data: data.frame
draw_geom: function
geom: <ggproto object: Class GeomRect, Geom>
aesthetics: function
default_aes: uneval
draw_group: function
draw_key: function
draw_layer: function
draw_panel: function
extra_params: na.rm
handle_na: function
non_missing_aes:
parameters: function
required_aes: xmin xmax ymin ymax
setup_data: function
use_defaults: function
super: <ggproto object: Class Geom>
geom_params: list
inherit.aes: FALSE
map_statistic: function
mapping: uneval
position: <ggproto object: Class PositionIdentity, Position>
compute_layer: function
compute_panel: function
required_aes:
setup_data: function
setup_params: function
super: <ggproto object: Class Position>
print: function
show.legend: FALSE
stat: <ggproto object: Class StatIdentity, Stat>
compute_group: function
compute_layer: function
compute_panel: function
default_aes: uneval
extra_params: na.rm
non_missing_aes:
parameters: function
required_aes:
retransform: TRUE
setup_data: function
setup_params: function
super: <ggproto object: Class Stat>
stat_params: list
subset: NULL
super: <ggproto object: Class Layer>
$ scales :Classes 'ScalesList', 'ggproto' <ggproto object: Class ScalesList>
add: function
clone: function
find: function
get_scales: function
has_scale: function
input: function
n: function
non_position_scales: function
scales: list
super: <ggproto object: Class ScalesList>
$ mapping :List of 2
..$ x: symbol lon
..$ y: symbol lat
$ theme : list()
$ coordinates:Classes 'CoordMap', 'Coord', 'ggproto' <ggproto object: Class CoordMap, Coord>
aspect: function
distance: function
is_linear: function
labels: function
limits: list
orientation: NULL
params: list
projection: mercator
range: function
render_axis_h: function
render_axis_v: function
render_bg: function
render_fg: function
train: function
transform: function
super: <ggproto object: Class CoordMap, Coord>
$ facet :List of 1
..$ shrink: logi TRUE
..- attr(*, "class")= chr [1:2] "null" "facet"
$ plot_env :<environment: 0x000000001fd04120>
$ labels :List of 6
..$ x : chr "lon"
..$ y : chr "lat"
..$ xmin: chr "xmin"
..$ xmax: chr "xmax"
..$ ymin: chr "ymin"
..$ ymax: chr "ymax"
- attr(*, "class")= chr [1:2] "gg" "ggplot"
> scale_size_continuous(range=range(mv_num_collisions$collisions))
<ScaleContinuous>
Range:
Limits: 0 -- 1
> #
> USAMap +
+ geom_point(aes(x=lon, y=lat), data=mv_num_collisions, col="orange", alpha=0.4) +
+ scale_size_continuous(range=range(mv_num_collisions$collisions))
Error in layer(data = data, mapping = mapping, stat = stat, geom = GeomPoint, :
object 'circle_scale_amt' not found
>
No comments:
Post a Comment