简体   繁体   English

如何标准化值以实现更好的可视化

[英]How to normalize the value for better visualization

I have a vector like this 我有一个这样的载体

> vec
  [1] 6252076  163554  199004   59339   13346   37514   14941    8757
  [9]   18009    9564   29090  212084    9221   27056   51972  131662
 [17]    6003   30280    1595    9837   32892   39490    5071   34630
 [25]    6063    3924   28652   23282   18016    9919    3259   26055
 [33]    2693   11050    2047    2845    5911   18121   11186   10678
 [41]    1240    2287    1708    4148    3229   33306    2571    1903
 [49]   30501    2741    1540    9129    2377    3464    1994    2414
 [57]    5545    1326    3272    3228    1586    4433    4933    1597
 [65]    1436    2324     735    1234    2321    3657    1055    3621
 [73]     382   11770    1414    1073     463    1022    3017    4631
 [81]    2578     889    2039     775    3037     600    1938    6973
 [89]     833     667     639    5218     843    1762    4144    4061
 [97]     420    1267     619    1174     347     236    1423   45820
[105]     929    3736     346     325     495     280     152

When I plot this data I get some thing similar to below picture. 当我绘制这些数据时,我得到的东西类似于下图。 http://s28.postimg.org/ugqmtmesd/Rplot.png http://s28.postimg.org/ugqmtmesd/Rplot.png

In this graph visual interpretation is difficult. 在此图中,视觉解释很困难。 So I tired to normalize the vec values by a custom function 所以我厌倦了通过自定义函数对vec值进行规范化

nor <- function(vec) {
  tem <- vector()
  max <- max(vec)
  min <- min(vec)
  for(v in vec){
    tem <- c(tem , (v - min) / (max - min))
  }
  return(tem)
}


  [1] 1.000000e+00 2.613627e-02 3.180653e-02 9.467006e-03
  [5] 2.110390e-03 5.976080e-03 2.365512e-03 1.376376e-03
  [9] 2.856241e-03 1.505457e-03 4.628655e-03 3.389868e-02
 [13] 1.450593e-03 4.303315e-03 8.288648e-03 2.103512e-02
 [17] 9.358719e-04 4.818997e-03 2.308089e-04 1.549123e-03
 [21] 5.236788e-03 6.292143e-03 7.867978e-04 5.514782e-03
 [25] 9.454689e-04 6.033343e-04 4.558597e-03 3.699661e-03
 [29] 2.857360e-03 1.562239e-03 4.969670e-04 4.143205e-03
 [33] 4.064349e-04 1.743143e-03 3.031067e-04 4.307474e-04
 [37] 9.211564e-04 2.874155e-03 1.764897e-03 1.683642e-03
 [41] 1.740264e-04 3.414949e-04 2.488834e-04 6.391632e-04
 [45] 4.921685e-04 5.303008e-03 3.869209e-04 2.800738e-04
 [49] 4.854346e-03 4.141125e-04 2.220117e-04 1.435878e-03
 [53] 3.558904e-04 5.297569e-04 2.946293e-04 3.618086e-04
 [57] 8.626145e-04 1.877822e-04 4.990464e-04 4.920085e-04
 [61] 2.293694e-04 6.847492e-04 7.647246e-04 2.311288e-04
 [65] 2.053768e-04 3.474131e-04 9.325129e-05 1.730667e-04
 [69] 3.469332e-04 5.606274e-04 1.444355e-04 5.548692e-04
 [73] 3.678867e-05 1.858308e-03 2.018579e-04 1.473147e-04
 [77] 4.974469e-05 1.391572e-04 4.582589e-04 7.164195e-04
 [81] 3.880405e-04 1.178837e-04 3.018271e-04 9.964932e-05
 [85] 4.614579e-04 7.165794e-05 2.856721e-04 1.091024e-03
 [89] 1.089265e-04 8.237464e-05 7.789602e-05 8.103106e-04
 [93] 1.105260e-04 2.575207e-04 6.385234e-04 6.252475e-04
 [97] 4.286680e-05 1.783451e-04 7.469701e-05 1.634697e-04
[101] 3.119040e-05 1.343586e-05 2.032974e-04 7.304631e-03
[105] 1.242817e-04 5.732635e-04 3.103045e-05 2.767148e-05
[109] 5.486311e-05 2.047370e-05 0.000000e+00

Plotting again I get the same graph. 再次绘图,我得到相同的图。 Is there any way I can normalize the value of vector to get a better graph for visualization. 有什么方法可以规范vector的值,以获得更好的可视化图形。

As suggested by alexwhan you could use log='y' to draw a logarithmic y-axis: 如alexwhan所建议,您可以使用log='y'绘制对数y轴:

vec <- c(6252076,  163554,  199004,   59339,   13346,   37514,   14941,    8757 ,
  18009,    9564,   29090,  212084,    9221,   27056,   51972,  131662,
   6003,   30280,    1595,    9837,   32892,   39490,    5071,   34630,
   6063,    3924,   28652,   23282,   18016,    9919,    3259,   26055,
   2693,   11050,    2047,    2845,    5911,   18121,   11186,   10678,
   1240,    2287,    1708,    4148,    3229,   33306,    2571,    1903,
  30501,    2741,    1540,    9129,    2377,    3464,    1994,    2414,
   5545,    1326,    3272,    3228,    1586,    4433,    4933,    1597,
   1436,    2324,     735,    1234,    2321,    3657,    1055,    3621,
    382,   11770,    1414,    1073,     463,    1022,    3017,    4631,
   2578,     889,    2039,     775,    3037,     600,    1938,    6973,
    833,     667,     639,    5218,     843,    1762,    4144,    4061,
    420,    1267,     619,    1174,     347,     236,    1423,   45820,
    929,    3736,     346,     325,     495,     280,     152)

barplot(vec, log='y')

对数y轴的条形图

Another solution is to truncate the first bar. 另一个解决方案是截断第一栏。 In the example below I indicated truncation by placing the truncated value above the bar. 在下面的示例中,我通过将截断的值放在条形上方来指示截断。 This could of course be refined. 这当然可以完善。

barplot(vec, ylim=c(0, max(vec[-1])), xpd=FALSE)
text(1, par("usr")[4], labels=vec[1], xpd=TRUE, pos=3, cex=0.8)

带截断条形的条形图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM