我有一系列有序点,如下所示:
但是,当我尝试通过一行连接点时,我得到以下输出:
该图连接26到1和25到9和10(一些错误),而不是遵循顺序.绘制点的代码如下:
p<-ggplot(aes(x = x, y = y), data = spat_loc)
p<-p + labs(x = "x Coords (Km)", y="Y coords (Km)") +ggtitle("Locations")
p<-p + geom_point(aes(color="Red",size=2)) + geom_text(aes(label = X))
p + theme_bw()
Run Code Online (Sandbox Code Playgroud)
并绘制我正在使用的线:p + geom_line((aes(x = x,y = y)),color ="blue")+ theme_bw()
包含位置的文件具有以下结构:
p +
geom_line((aes(x=x, y=y)),colour="blue") +
theme_bw()
Run Code Online (Sandbox Code Playgroud)
其中X是数字ID,x和y是坐标对.
我需要做什么才能使线条遵循点的顺序?
ale*_*han 27
geom_path()
将按原始订单加入积分,这样您就可以按照加入的方式订购数据,然后就可以了+ geom_path()
.这是一些虚拟数据:
dat <- data.frame(x = sample(1:10), y = sample(1:10), order = sample(1:10))
ggplot(dat[order(dat$order),], aes(x, y)) + geom_point() + geom_text(aes(y = y + 0.25,label = order)) +
geom_path()
Run Code Online (Sandbox Code Playgroud)