我正在尝试使用ggmap从csv绘制点。输入的csv具有纬度,经度和十六进制颜色值(以及用于创建颜色值的种子)。但是,该点的十六进制与该点的实际颜色不匹配。为什么会这样?
我的代码:
library(ggmap)
stores <- data.frame((read.csv(file="./mapData")
# Fetch the map
madison = get_map(location = location, source = "osm")
# Draw the map
madisonMap = ggmap(madison)
# Add the points layer
madisonMap = madisonMap +
geom_point(data = stores,
aes(x = Longitude, y = Latitude, colour = Color),
size = 5)
数据集的示例子节:
Latitude, Longitude, Seed, Color
45.508785, -122.632101 , 8, #22DD00
45.515093, -122.642574, 11, #55AA00
45.485144, -122.596184, 15.3, #9F6000
如果将颜色映射为十六进制值,则ggplot默认会将其解释为字符串。要使其解析为颜色,请添加+ scale_color_identity()
。
ggplot(mtcars[1:30,] %>%
mutate(color = rep(c("#22DD00", "#55AA00", "#9F6000"), times = 10)),
aes(wt, mpg, color = color)) +
geom_point()
ggplot(mtcars[1:30,] %>%
mutate(color = rep(c("#22DD00", "#55AA00", "#9F6000"), times = 10)),
aes(wt, mpg, color = color)) +
geom_point() +
scale_color_identity()