【发布时间】:2019-03-30 03:53:50
【问题描述】:
我有一个数据框列“位置”,它是一个包含 8 个级别(“site01”、“site02”、“site03”、“site04”......“site08”)的因子,每个级别都有一个纬度和经度作为数据框中的另外两列。
我需要做一个分面网格并根据站点的纬度对站点进行排序。
我已尝试对列进行排序,但它对 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
这会生成图,但它们不是根据站点的纬度排序的。
【问题讨论】:
-
欢迎来到 Stack Overflow!您能否通过共享您的数据样本来重现您的问题,以便其他人可以提供帮助(请不要使用
str()、head()或屏幕截图)?您可以使用reprex和datapasta包来帮助您。另见Help me Help you & How to make a great R reproducible example?