Вот часть кода RR 3.2.1, реверс цвета на карте
# create a new grouping variable
Percent_SEP12_Assets <- ifelse(sep[,8] <= 33, "Lower Third", ifelse(sep[,8] >= 55, "Upper Third", "Middle Third"))
# get the map
bbox <- make_bbox(sep$Longitude, sep$Latitude, f = 0.3)
map <- get_map(bbox)
# plot the map and use the grouping variable for the fill inside the aes
ggmap(map) +
geom_point(data=sep, aes(x = Longitude, y = Latitude, color=Percent_SEP12_Assets), size=5, alpha=0.6) +
scale_color_manual(breaks=c("Upper Third", "Middle Third","Lower Third"), values=c("green","orange","red"))
Но вместо карты делает
«верхней трети» соответствуют с зеленым «средней трети» соответствуют Orange «Нижняя треть» соответствуют красным
Цветовая схема смешана, т.е. верхняя третья соответствует красной, а нижняя третья соответствует зеленому.
Более высокие цифры = хорошие = зеленые, но карта показывает противоположную. Как это исправить?
То, что я пытался до сих пор
Следующий код
# create a new grouping variable
Percent_SEP12_Assets <- ifelse(sep[,8] <= 33, "Lower Third", ifelse(sep[,8] >= 55, "Upper Third", "Middle Third"))
Percent_SEP12_Assets <- factor(Percent_SEP12_Assets)
levels(Percent_SEP12_Assets) <- c("Upper Third", "Middle Third", "Lower Third")
# get the map
bbox <- make_bbox(sep$Longitude, sep$Latitude, f = 0.3)
map <- get_map(bbox)
# plot the map and use the grouping variable for the fill inside the aes
ggmap(map) +
geom_point(data=sep, aes(x = Longitude, y = Latitude, color=Percent_SEP12_Assets), size=9, alpha=0.6) +
scale_color_manual(values=c("green","orange","red"))
Даст это, который корректирует метки данных, но точки в карте инвертируются, т.е. там, где это зеленый, красный и наоборот (точки в синем круге должны быть красными)
Но когда я отменил «красный» и «зеленый» в исходном коде, он работает (область в синем круге предполагается, красный), но я считаю, что это «лейкопластырь» подход
# create a new grouping variable
Percent_SEP12_Assets <- ifelse(sep[,8] <= 33, "Lower Third", ifelse(sep[,8] >= 55, "Upper Third", "Middle Third"))
# get the map
bbox <- make_bbox(sep$Longitude, sep$Latitude, f = 0.3)
map <- get_map(bbox)
# plot the map and use the grouping variable for the fill inside the aes
ggmap(map) +
geom_point(data=sep, aes(x = Longitude, y = Latitude, color=Percent_SEP12_Assets), size=9, alpha=0.6) +
scale_color_manual(breaks=c("Upper Third", "Middle Third","Lower Third"), values=c("red","orange","green"))
Вы имеете в виду превратит 'Percent_SEP12_Assets' в переменный факторе после того, как делает его переменные группы с' Percent_SEP12_Assets <- ifelse (sep [, 8] <= 33, «Lower Third», ifelse (sep [, 8]> = 66, «Верхняя треть», «Средняя треть»)) '? – Rhonda
Да, точно. Я изменил свой ответ на это. – christoph
Все еще не работает :-(Однако, если я переключаю «красный» на «зеленый» в своем индивидуальном коде, тогда он работает. Ваш код выглядит правильно, почему он не работает для меня? – Rhonda