oswaldosantos / ggsn

R package to add north symbols and scale bars to maps created with ggplot or ggmap
http://oswaldosantos.github.io/ggsn/
GNU General Public License v2.0
161 stars 9 forks source link

using scalebar with facet_grid rearranges the facet levels into alphabetical order #20

Closed vermouthmjl closed 7 years ago

vermouthmjl commented 7 years ago

Here is an example.

library(ggsn)
library(ggplot2)

levls = c("A", "B", "C")
tmp_data= expand.grid(type = levls,
            long = 1:10)
tmp_data$lat = runif(10)

tmp_data$type = factor(tmp_data$type, levels = levls[c(2,1,3)])

g = ggplot(data = tmp_data, aes(x = long, y = lat)) + facet_grid(.~type) + geom_point()
g

g + scalebar(data = tmp_data, location = "topright", facet.var = "type", 
             facet.lev = "B", dd2km = FALSE,dist = 0.1)

I'd like to be able to conserve a specific order for the levels in the facetting variable. However, using scalebar seems to rearrange them into alphabetical order.

oswaldosantos commented 7 years ago

Check the version 0.4.4.

library(devtools)
install_github("oswaldosantos/ggsn")
vermouthmjl commented 7 years ago

Great! Thanks. I'll close the issue.