R 3.2.1,地图上的反色
R 3.2.1, reverse colors on map
这里是部分R代码
# 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"))
但不是制作地图
“上三分之一”对应于绿色
“中间三分之一”对应橙色
“下三分之一”对应于红色
配色方案混乱,即上三分之一对应红色,下三分之一对应绿色。
更高的数字 = 好 = 绿色,但地图显示相反。如何解决这个问题?
到目前为止我尝试了什么
以下代码
# 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
转化为因子变量并指定水平顺序:
# 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 = 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=5, alpha=0.6) +
scale_color_manual(values=c("green","orange","red"))
这里是部分R代码
# 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"))
但不是制作地图
“上三分之一”对应于绿色 “中间三分之一”对应橙色 “下三分之一”对应于红色
配色方案混乱,即上三分之一对应红色,下三分之一对应绿色。
更高的数字 = 好 = 绿色,但地图显示相反。如何解决这个问题?
到目前为止我尝试了什么
以下代码
# 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
转化为因子变量并指定水平顺序:
# 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 = 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=5, alpha=0.6) +
scale_color_manual(values=c("green","orange","red"))