нарисовать траекторию точек в r (функции слияния) - PullRequest
0 голосов
/ 04 декабря 2018
rm(list=ls())
setwd("C:/users/bok/Desktop")

library(leaflet)
library(readxl)
library(ggplot2)

myData<-read_excel("gggg.xlsx", sheet="Sheet4")


leaflet(structure(list(lat=as.numeric(myData$x), lon=as.numeric(myData$y)))) %>%
  addPolylines(lng=~lon, lat=~lat)%>%
  ggplot(myData, aes(x,y))+
  annotate("rect",xmin=Inf,xmax=0,ymin=Inf,ymax=0, fill= "red")  + 
  annotate("rect",xmin=-Inf,xmax=0,ymin=-Inf,ymax=0 , fill= "blue") + 
  annotate("rect",xmin=0,xmax=Inf,ymin=0, ymax=-Inf, fill= "yellow") + 
  annotate("rect",xmin=0,xmax=-Inf,ymin=Inf,ymax=0, fill= "green") + 
  geom_point()+xlim(-10,10)+ylim(-10,10)

myData - это просто координаты x, y .. Результат - просто квадранты с точками на цветном фоне. Как объединить две функции leafet () и ggplot () ??

enter image description here

1 Ответ

0 голосов
/ 04 декабря 2018
myData<-read_excel("gggg.xlsx", sheet="Sheet4")


myfunc<-function(df){
  ggplot(df, aes(x,y))+
  annotate("rect",xmin=Inf,xmax=0,ymin=Inf,ymax=0, fill= "red")  + 
  annotate("rect",xmin=-Inf,xmax=0,ymin=-Inf,ymax=0 , fill= "blue") + 
  annotate("rect",xmin=0,xmax=Inf,ymin=0, ymax=-Inf, fill= "yellow") + 
  annotate("rect",xmin=0,xmax=-Inf,ymin=Inf,ymax=0, fill= "green") + 
  geom_point()+xlim(-10,10)+ylim(-10,10)
}


leaflet(structure(list(lat=as.numeric(myData$x), lon=as.numeric(myData$y)))) %>%
  addTiles(myfunc(myData)) %>%
  addPolylines(lng=~lon, lat=~lat, color=~col)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...