R 按ggmap中的图例顺序排序
如何对ggmap中的图例顺序进行排序?我有以下代码:R 按ggmap中的图例顺序排序,r,legend,ggmap,R,Legend,Ggmap,如何对ggmap中的图例顺序进行排序?我有以下代码: mymap <- ggmap(map) + geom_point(data = mypoints, aes(x =lon, y= lat,colour = month), alpha=0.5, size=5) mymap编辑 正如Tyler Rinker所述,一种方法是使用函数factor来排序因子级别(在本例中为月)。 我创建了一些用于ggplot的数据,但是您可以调整数据并使用ggmap的逻辑 library(ggplot) x
mymap <- ggmap(map) + geom_point(data = mypoints, aes(x =lon, y= lat,colour = month), alpha=0.5, size=5)
mymap编辑
正如Tyler Rinker所述,一种方法是使用函数factor
来排序因子级别(在本例中为月)。
我创建了一些用于ggplot的数据,但是您可以调整数据并使用ggmap的逻辑
library(ggplot)
x = c(6.2, 2.3, 0, 1.54, 2.17, 6.11, 0.3,
1.39, 5.14, 12.52, 12.57, 7.13, 13.71)
y = c(7.89, 7.63, 5.29, 8.38, 8.37, 10.5, 21.5,
16.65, 23.76, 1.77, 1.8, 10.49, 14.01)
month = month.abb # system constant in correct sort order.
mypoints = data.frame(cbind(x,y,month))
mypoints$month = factor(mypoints$month,
levels=month.abb )
ggplot(data = mypoints,aes(x,y)) +
geom_point(aes(color=month), alpha=0.5, size=5)
看看:这不是关于ggplot,而是关于因子水平。