цвет geom_point неверен - PullRequest
       15

цвет geom_point неверен

1 голос
/ 04 октября 2019

Я пытаюсь построить точки из CSV, используя ggmap. Входной 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

Ответы [ 2 ]

2 голосов
/ 04 октября 2019

Если вы сопоставите цвет с шестнадцатеричным значением, ggplot по умолчанию интерпретирует его как строку символов. Чтобы сделать это в качестве цвета, добавьте + scale_color_identity().

ggplot(mtcars[1:30,] %>% 
         mutate(color = rep(c("#22DD00", "#55AA00", "#9F6000"), times = 10)), 
       aes(wt, mpg, color = color)) +
  geom_point()

enter image description here

ggplot(mtcars[1:30,] %>% 
         mutate(color = rep(c("#22DD00", "#55AA00", "#9F6000"), times = 10)), 
       aes(wt, mpg, color = color)) +
  geom_point() +
  scale_color_identity()

enter image description here

0 голосов
/ 04 октября 2019

Вам нужно добавить его с scale_colour_manual Я предполагаю, что цвет должен представлять Семя

madisonMap = madisonMap + geom_point(data = stores, aes(x = Longitude, y = Latitude,colour=as.factor(Seed)), size = 5) + 
                      scale_colour_manual(values=stores$Color,labels=as.factor(stores$Seed),name='Seed')

enter image description here

...