以下是我的数据
Name datetime latitude longitude mode
A 2016-01-11 02:00:04 PST 40.07054 -76.288572 Cycle
A 2016-01-11 02:10:04 PST 39.82271579 -77.2300438 Cycle
A 2016-01-11 02:20:04 PST 39.83636098 -77.2061907 Cycle
B 2016-01-02 03:55:58 PST 40.009918 -75.188196 Car
B 2016-01-02 03:59:58 PST 39.94432271 -76.5933571 Car
B 2016-01-02 04:10:58 PST 39.91651225 -77.1641403 Car
我想绘制每个用户沿着日期时间所采用的路径。输出显示为图形中的不同路径,其中每个路径用于一个用户,并且在每个纬度和经度中显示日期和时间,并且还沿路径显示模式。我不知道如何在R中这样做。任何人都可以帮我这样做吗?
以下是可重现的例子,
names = c('A','A','A','B','B','B')
datetime = c('2016-01-11 02:00:04 PST','2016-01-11 02:10:04 PST','2016-01-11 02:20:04 PST','2016-01-02 03:55:58 PST','2016-01-02 03:59:58 PST','2016-01-02 04:10:58 PST')
latitude = c(40.07054,39.82271579,39.83636098, 40.009918,39.94432271,39.91651225)
longitude = c(-76.288572, -77.2300438, -77.2061907,-75.188196, -76.5933571, -77.1641403)
mode = c('Bike','Bike','Bike','Car','Car','Car')
test = data.frame(names,datetime,latitude,longitude,mode)
有人可以帮助我或建议一些方法来绘制这些图表吗?
更新:
以下是我的尝试,
library(ggplot2)
library(ggmap)
map <- get_map(location = c(lon = mean(test$longitude), lat = mean(test$latitude)), zoom = 4, maptype = "satellite", scale = 2)
basicmap <- ggmap(map)
basicmap + geom_path(data=test,aes(x=longitude, y=latitude, group=names, color=route),size=1)
但我得到了,
Don't know how to automatically pick scale for object of type function. Defaulting to continuous
Error in data.frame(x = c(-76.288572, -77.2300438, -77.2061907, -75.188196, :
arguments imply differing number of rows: 6, 0
由于
答案 0 :(得分:2)
template<typename T>
class Matrix
{
template<typename U>
friend
Matrix<U> operator+(const Matrix<U>& a, const Matrix<U>& b);
protected:
size_t _m, _n;
T *_alloc;
};
template<typename U>
Matrix<U> operator+(const Matrix<U>& a, const Matrix<U>& b)
{
if(a._m == b._m && a._n == b._n)
{
Matrix<U> ret(a._m, a._n);
// ...
return ret;
}
else
{
throw "Matrix dimension mismatch error";
}
}
花一些时间来改变颜色,轴和其他东西,使其更具代表性,但这应该让你开始。