GGMAP传奇未显示
我有两个数据范围都记录了前10个电台骑手的走了。一个是为了休闲骑手,另一个是为成员骑手。两个数据范围都包含列“站”,“ freq”,“ Latitude”,“经度”。我能够使用GGMAP绘制图形,显示两个数据范围内的电台位置,但无法显示传说。 R scripe如下所示:
library(ggplot2)
library(rstudioapi)
library(ggmap)
map_location <- c (lon = -87.623177, lat = 41.881832)
chicago_map_zoom <- get_map (location = map_location,
maptype = 'roadmap',
color='bw',
source='google',
zoom=13,
)
chicago_plot <- ggmap(chicago_map_zoom) +
geom_point (data = casual_top_station,
aes (x = longitude,
y = latitude),
color = "red",
shape = 15,
alpha = 0.5,
size = 3) +
geom_point (data = member_top_station,
aes (x = longitude,
y = latitude),
color = "blue",
shape = 16,
alpha = 0.5,
size = 2) +
scale_color_identity (name = "Subscription type",
breaks = c("red","blue"),
labels = c("Casual","Member"),
guide = "legend") +
theme (axis.ticks = element_blank(),
axis.text = element_blank(),
axis.title = element_blank()) +
labs (title = "Top 10 casual and member rider stations",
subtitle = "Both start and end stations")
结果图: chicago_map
I have two dataframes both recording the top 10 stations riders went. One is for casual rider, the other one is for member rider. Both dataframes contain column 'station','freq','latitude','longitude'. I'm able to use ggmap to plot the graph showing the locations of the stations from both dataframes, but not able to show the legend.
R scripe is showing below:
library(ggplot2)
library(rstudioapi)
library(ggmap)
map_location <- c (lon = -87.623177, lat = 41.881832)
chicago_map_zoom <- get_map (location = map_location,
maptype = 'roadmap',
color='bw',
source='google',
zoom=13,
)
chicago_plot <- ggmap(chicago_map_zoom) +
geom_point (data = casual_top_station,
aes (x = longitude,
y = latitude),
color = "red",
shape = 15,
alpha = 0.5,
size = 3) +
geom_point (data = member_top_station,
aes (x = longitude,
y = latitude),
color = "blue",
shape = 16,
alpha = 0.5,
size = 2) +
scale_color_identity (name = "Subscription type",
breaks = c("red","blue"),
labels = c("Casual","Member"),
guide = "legend") +
theme (axis.ticks = element_blank(),
axis.text = element_blank(),
axis.title = element_blank()) +
labs (title = "Top 10 casual and member rider stations",
subtitle = "Both start and end stations")
Result graph: Chicago_map
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是使用
scale_color_identity
...为了设置颜色,形状和大小的值,我建议您首先将ID
列列到您的data.frames然后可以在
aes
内的美学上映射。之后,通过scale_xxx_manual
函数系列设置所需的颜色,形状和大小。使用一些虚假数据来点:
,为了进一步简化代码例如
dplyr :: bind_rows
,它将仅通过一个geom_point
添加您的点。Instead of using
scale_color_identity
... to set the values for color, shape and size I would suggest to first anid
column to your data.frameswhich could then be mapped on aesthetics inside
aes
. Afterwards set your desired colors, shapes and sizes via thescale_xxx_manual
family of functions.Using some fake data for the points:
Also, to simplify your code further I would suggest to bind both data frames by row using e.g.
dplyr::bind_rows
which would allow to add your points via just onegeom_point
.