r - R 中的 3D 极坐标图

标签 r ggplot2 polar-coordinates

我使用 ggplot2 绘制了数据的极坐标。

我的数据集采用以下格式:

 Time    Lat    Long   Act
 18:00  21.05   70.00  feed
 18:45  21.00   75.00  walk
 19:00  21.09   77.00  walk
 19:05  24.98   77.09  rest

代码:

library(ggplot2)
plot.new()

ggplot(aes(x = Lat, y = Long, colour = Act), data = file) + 
geom_point() 
ggplot(aes(x= Lat, y = Long , colour = Act), data = file) + 
geom_point() + 
coord_polar(theta = "y")

这是我得到的极坐标图: here

该图具有纬度和经度。现在我想再增加一个维度“时间”。我怎样才能做到这一点 ?。如何在 3D 极坐标图中绘制 2D 极坐标图?

最佳答案

您可以尝试使用变量“时间”的值来缩放点的大小。不幸的是,您的示例不可重现,但以下内容可能有效:

ggplot(aes(x= Latitude, y = Longitude , colour = ACTIVITY, size=time), data = Data) + geom_point(shape=21) + coord_polar(theta = "y") + scale_size_area(max_size=10)

下面您可以看到一个可重现的示例,该示例基于 Winston Chang 的“The R Graphics Cookbook”(O'Reilly 2013)中使用的数据。

在本例中,点大小代表温度,颜色代表风速类别,风向以极坐标绘制,半径为风的平均值。

library(gcookbook)
library(ggplot2)
p <- ggplot(wind, aes(x=WindDir, y=WindAvg, size=Temp, fill=SpeedCat)) +
     coord_polar() + geom_point(shape=21)+scale_size_area(max_size=10) +
     scale_x_continuous(limits=c(0,360),breaks=seq(0,360,by=45))

这是输出: enter image description here

希望这有帮助。

关于r - R 中的 3D 极坐标图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31109164/

相关文章:

r - 在循环内使用 ggplot2 的直方图

r - 不连续图 - R 中的 ggplot

php - 模糊比较两个表的最佳方法是什么

R 在运行 rworldmap 时找不到函数 "checkAtAssignment"

r - 如何cbind在R中的循环中生成的列

r - data.table 默认外部连接与 setkey,计算行(列出键的频率)

r - 整个facet_grid的极坐标/圆形布局

ios - 使用 UIBezierPath 绘制极坐标函数

r-ggplot2 : connecting points in polar coordinates with a straight line

python - 风玫瑰图的自定义缩放