如何使用R包循环在360上创建直方图数据的玫瑰图。 [英] How to use R package circular to make rose plot of histogram data on 360.

查看:123
本文介绍了如何使用R包循环在360上创建直方图数据的玫瑰图。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对R(或任何类型的编码)非常缺乏经验,但我正在尝试使用来自单元格的定向数据的封装圆形来制作玫瑰图。基本上,我创建了一个直方图来定位这些单元格,现在我想在圆形图上绘制这些数据,以显示x单元格类型更倾向于比y单元格类型的东西。
我需要将数据放在度数图上,而不是默认的pi值。
有人可以帮我吗?我还没有找到任何可以插入数据的东西,只是很多风玫瑰图的气象代码没有用处。正如我所说的,非常新的这一点。 解决方案

这是第一次尝试。假设你的数据在dataframe d 中,我已经在下面重新创建了它(为 Angle添加一行= 250 ,上面的评论中似乎没有):

  d < -  structure(list(Angle = c(0,10, 20,30,40,50,60,70,80,90,
100,110,120,130,140,​​150,160,170,180,190,200,210,220,
230,240,260,270,280,290,300,310,320,330,340,350,250
),频率= c(0,0,0.001,2,4,18.03,11,12 ,5,7,10,
13,2,0.003,0.01,0,1,0.05,2,3,3.7,6,0,0,0,0,0,
0.006,0 ,0,0,0,0,0,0)),.Names = c(Angle,Frequency
),row.names = c(NA,36L),class =data .frame)
str(d)
#'data.frame':36 obs。 2个变量:
#$角度:num 0 10 20 30 40 50 60 70 80 90 ...
#$频率:num 0 0 0.001 2 4 ...

我们可以使用 ggplot

  library(ggplot2)
ggplot(d,aes(x = Angle,y = Frequency))+
coord_polar(theta =x, start = -pi / 45)+
geom_bar(stat =identity)+
scale_x_continuous(breaks = seq(0,360,60))


I'm very inexperienced with R (or any type of coding), but I'm trying to make a rose plot using the package circular for directional data from cells. Essentially, I have created a histogram for orientation of these cells and now I want to plot that data on a circular graph to show "x" cell type is more oriented towards something than "y" cell type. I need the data to be on a graph of degrees, rather than the default pi. Can someone help me out? I haven't found anything that I can plug my data into, just a lot of meteorological codes for wind rose-plots that aren't useful. Like I said, VERY new to this.

解决方案

Here is a first attempt. Suppose your data is in dataframe d, which I've recreated below (adding a row for Angle = 250, which appears to be missing from your comment above):

d <- structure(list(Angle = c(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 
100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 
230, 240, 260, 270, 280, 290, 300, 310, 320, 330, 340, 350, 250
), Frequency = c(0, 0, 0.001, 2, 4, 18.03, 11, 12, 5, 7, 10, 
13, 2, 0.003, 0.01, 0, 1, 0.05, 2, 3, 3.7, 6, 0, 0, 0, 0, 0.2, 
0.006, 0, 0, 0, 0, 0, 0, 0, 0)), .Names = c("Angle", "Frequency"
), row.names = c(NA, 36L), class = "data.frame")
str(d)
# 'data.frame': 36 obs. of  2 variables:
#  $ Angle    : num  0 10 20 30 40 50 60 70 80 90 ...
#  $ Frequency: num  0 0 0.001 2 4 ...

We can use ggplot:

library(ggplot2)
ggplot(d, aes(x = Angle, y = Frequency)) +
  coord_polar(theta = "x", start = -pi/45) +
  geom_bar(stat = "identity") +
  scale_x_continuous(breaks = seq(0, 360, 60))

这篇关于如何使用R包循环在360上创建直方图数据的玫瑰图。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆