我正在使用以下语法绘制说X和Y之间的散点图(x轴上的X和y轴上的Y)。
情节(X,Y)
X和Y都是连续变量。
现在,我希望在此散点图上获得频率图(直方图)。例如。让我们说散点图中的X从0到5不等。所以,我想得到每个X长度为1的区间的频率图。所以,对于[0-1]中的X,会有一个条形,对于X在[1-2]秒栏中,X在[2-3]第三栏中,依此类推。
修改 直方图可能会掩盖散射的大部分。所以,即使我得到的数字对应于在地块上某处写的条(也就是在顶部)也会这样(在这种情况下没有条形)。我只需要了解不同范围的频率(如条形或数字)。
如何在R中实现这一目标?
一个非常小的样本的输入。
structure(list(X = c(0.00141030838064132, 0.000494776986570204,
0.000420637540743273, 0.000416330553562312, 0.000327605678810922,
0.000334769111670038, 0.000176362745989615, 0.000353032500825868,
0.000284234369907286, 8.1733706680748e-05, 0.00040641582048246,
8.11457783908792e-05, 8.0837382794669e-05, 0.000180929590411692,
7.34138519774738e-05, 8.11457783908792e-05, 0.000180489447700001,
8.11457783908792e-05, 8.11457783908792e-05, 8.11457783908792e-05,
7.59364670335551e-05, 8.11366624312646e-05, 8.07716946874238e-05,
8.11457783908792e-05, 7.94865358399697e-05, 8.11363186345391e-05,
8.08682289898023e-05, 8.11457783908792e-05, 8.11457783908792e-05,
8.10380699582227e-05, 8.11457783908792e-05, 8.11457783908792e-05,
8.10597920106679e-05, 8.11457783908792e-05, 7.99543191487116e-05,
8.11457783908792e-05, 8.04154336817913e-05, 8.11040375814918e-05,
8.11457783908792e-05, 8.11457783908792e-05, 0.000115930065130829,
0, 0.00149708061666934, 0.000259968018664645, 0.000252569769878596,
0.000272319502600671, 1.55688321576032e-05, 0.00288760062956232,
0.000231670000469685, 7.83115248647628e-05, 0.000640384230538323,
0.000698932964979634, 0.000595671591321322, 0.000538765242449338,
0.000765226541647779, 0.000587799953746904, 0.000655947982777194,
0.000402366287651635, 0.00063891536109952, 0.000213812430974318,
0.000564814230989396, 0.000201566507273599, 0.000542942589765765,
0.000640384230538323, 0.000640384230538323, 0.000640384230538323,
0.000910553716031754, 0.000722077439151928, 0.000474200650778307,
0.000116662171252828, 0, 0, 0.000142960473164439, 0, 8.46636778817535e-05,
0, 0, 0.00118718015299255, 0.000458686951174685, 0.000139951761307805,
0.000412851997311128, 8.85804022332864e-05, 0.000301084760362437,
2.81047907806604e-05, 0.000139526441696557, 0.000128095170697041,
6.90398423104225e-05, 1.45278932213477e-05, 0.000121815916084411,
0.00014369483584908, 0, 0.000118108327984086, 5.84788165557941e-05,
0.000129959996409527, 0.000133080075718582, 0.00013192258835621,
0.000132535040379761, 0.000232951960667621, 0.000132356598534841,
0.000133682865059176), Y = c(2.44160223530961e-06, 4.32697911760654e-07,
7.28671581824204e-07, 7.84051631144022e-07, 1.49857280230364e-07,
4.42449893419501e-07, 3.60364826955947e-07, 4.66191261960537e-07,
3.16997496383143e-07, 2.37850594276965e-07, 4.27127571638305e-07,
1.8043281515139e-07, 1.58857206660122e-07, 1.01436449014835e-07,
2.19121836415415e-07, 9.17178201531101e-08, 8.1055328062058e-08,
1.08543082127821e-07, 2.37371597342348e-07, 2.24014612697305e-07,
1.80966979034231e-07, 1.72812312121038e-07, 2.45547707661429e-07,
1.75937297851997e-07, 1.86798308192844e-07, 1.5298361416559e-07,
1.63279483827935e-07, 1.00573634637651e-07, 7.13682637405445e-08,
2.39123470964322e-07, 2.26638075403414e-07, 1.83133361992077e-07,
2.04672970252807e-07, 4.6181672198457e-08, 1.39358166991606e-07,
1.97063969072651e-07, 8.56155084029855e-08, 1.06540549772715e-07,
8.87443726998921e-08, 7.04813613555759e-08, 1.30594177490294e-07,
7.62557591852037e-08, 1.43634658915428e-06, 1.59657677606683e-07,
1.45064318575815e-07, 1.97426903401167e-07, 8.33922027413303e-08,
1.01595071050062e-06, 4.23237426396923e-07, 5.02256932665429e-08,
5.3136081345117e-07, 8.84595841358677e-07, 2.57979560107636e-07,
5.48895545821489e-07, 3.78459760153572e-07, 2.51220673457457e-07,
7.93205331143823e-07, 7.08644863444902e-07, 4.75314501123384e-07,
3.1824555227723e-07, 2.1736608233363e-07, 2.10137999981753e-07,
3.41783665158596e-07, 8.39520233762751e-07, 5.36586936905755e-07,
8.35734279442903e-07, 1.42006858503491e-06, 8.81082298452859e-07,
4.58820539595698e-07, 2.03280871672928e-07, 1.03031416892225e-07,
1.13090922158804e-07, 5.2333059218234e-08, 8.39086473222456e-08,
8.65586947570376e-08, 7.20426881871566e-08, 1.00987474738825e-07,
8.70845576365621e-07, 2.15037446443111e-07, 1.16765276937208e-07,
5.69984738663679e-07, 1.27528196133943e-07, 5.2860614256513e-07,
4.95092076627282e-08, 1.66774637700855e-07, 2.59807590834898e-07,
2.15927807826023e-07, 1.35475385072329e-07, 8.04043348820979e-08,
8.62621147081329e-08, 1.05998625390818e-07, 1.15756288940413e-07,
1.63617432597157e-07, 1.15577606551361e-07, 8.75307480186725e-08,
2.19571702322701e-07, 6.61603492359945e-08, 2.71772452724646e-07,
1.59606589766817e-07, 1.81449721904323e-07)), .Names = c("X",
"Y"), row.names = c(NA, 100L), class = "data.frame")
答案 0 :(得分:2)
x = randu * 10 # load some data
h = hist(x$x, breaks = max(x$x)-min(x$x)) # plot a histogram
par(new=TRUE) # new plot
plot(x$x, x$y,,type="p",col="blue",xaxt="n",yaxt="n",xlab="",ylab="")
# plot your points but no axes
axis(4) # draw axis on side "4"
randu只是一些数据。我乘以它是10来演示你想要的休息时间。 hist,绘制直方图。 h包含您感兴趣的数据。 Breaks为您提供了将数据放入的箱数......在这种情况下,数据的范围将为宽度为1的箱子提供。
<强>更新强>
使用您的数据:
h = hist(x$X, breaks = 15)
par(new=TRUE)
plot(x$X, x$Y,,type="p",col="blue",xaxt="n",yaxt="n",xlab="",ylab="")
axis(4)
给了我:
(显然,我把你的数据放到x中)
同时强>
您可能希望查看您的数据日志转换...它已经完全成束了!
l = log2(x)
h = hist(l$X, breaks = 15)
par(new=TRUE)
plot(l$X, l$Y,,type="p",col="blue",xaxt="n",yaxt="n",xlab="",ylab="")
axis(4)