I have a dataframe column 'location' which is a factor with 8 levels ('site01', 'site02', 'site03', 'site04' ..... 'site08') each of which have a latitude and longitude as two other columns in the dataframe.
I need to do a facet grid and order the sites according to the latitudes of the sites.
I have tried ordering the column but it doesn't have any effect on the plot produced by ggplot2.
library(scales)
library(ggplot2)
sp <- ggplot(df, aes(x=year, y=value, col=coralType)) + geom_point(stat="identity") + facet_grid(location ~ coralType) +
theme(strip.text.x = element_text(size=8),
strip.text.y = element_text(size=8, face="bold", angle = 0),
strip.background = element_rect(colour="red", fill="#CCCCFF")) +
scale_x_continuous(name="Year", breaks=c(2010, 2013, 2016)) +
scale_y_continuous(name="Bleaching Percentage", breaks=seq(0,1,0.5), labels=percent)+
geom_smooth(method="lm")
sp
This produces the plots but they are not ordered according to the latitude of the site.