本文原创,转载请注明出处,本人Q1273314690(交流学习)
 
哭晕
你真的学会了stem()函数了吗?
stem()函数的使用方法是:
stem(x, scale=1,width=80, atom=le-08)
其中x是数据向量.
scale控制绘出茎叶图的长度.
width绘图的宽度.
atom是容差,如果选择scale=2,即将10个个位数俞成两段,0~4为一段,5~9为另一段。
然而事实上,我经过反复的试验,发现width最好取较大的数,他既不表示数据的取值范围也不表示最长的那片叶子的长度,也不表示所有的数据的个数
 
With the default scale, you see that numbers left of the bar go up by two - hence anything after the 4 is forty-something(四十几) or fifty-something(五十几):
 
  1. d<-c(60,85,72,59,37,75,93,7,98,63,41,90,5,17,97)
  2. > stem(d,scale=1)
  3.   The decimal point is 1 digit(s) to the right of the |
  4.  
  5.   0|577
  6.   2|7
  7.   4|19
  8.   6|0325
  9.   8|50378
Using scale=2, you'll see numbers left of the bar go up by one, so now you can get exact reconstruction(再造) of your input, since you input integers:
 
  1. > stem(d,scale=2)
  2.  
  3.   The decimal point is 1 digit(s) to the right of the |
  4.  
  5.   0|57
  6.   1|7
  7.   2|
  8.   3|7
  9.   4|1
  10.   5|9
  11.   6|03
  12.   7|25
  13.   8|5
  14.   9|0378
 
Going further you can even split it by first and second five within each decade:
 
  1. > stem(d,scale=4)
  2.  
  3.   The decimal point is 1 digit(s) to the right of the |
  4.  
  5.   0|57
  6.   1|      
  7.   1|7
  8.   2|
  9.   2|
  10.   3|
  11.   3|7
  12.   4|1
  13.   4|
  14.   5|
  15.   5|9
  16.   6|03
  17.   6|
  18.   7|2
  19.   7|5
  20.   8|
  21.   8|5
  22.   9|03
  23.   9|78
Stem plots do not always guarantee you can reproduce the data by reversing the process, and that's not what they're for.
 
This is probably more of a Stack Overflow question than a CV question, because it focuses on how R works and why, rather than the statistical aspects of stem and leaf plots. Nonetheless...
The way the function is coded is designed to shorten the length of the output, so that it better fits in the console. Few people, I believe, find that terribly helpful, or at least I don't. Just always remember to start with scale=2, and you may have to play with it further or adjust the width argument. Also, know that there is a fancier偏好者,(发烧友的比较级) version stem.leaf() in Rcmdr. 
 
 
总结:
R的stem函数其实是一个比较糟糕的设计,由于其设计的初衷是让其在控制台上能尽量简短的显示(否则控制台宽度不够),所以,当数据之间的差距较大的时候,就会出问题,他会跳着提升枝干,所以一般要设置sacle,而sacle设置的越大,分茎越多,精度越高,如果你的scale较小,他甚至会自动帮你的数据做四舍五入(这样会降低精度)
> test<-c(57,122,1000)
> stem(test,scale = 2)
 
  The decimal point is 2 digit(s) to the right of the |
 
   0 | 6
   1 | 2
   2 |
   3 |
   4 |
   5 |
   6 |
   7 |
   8 |
   9 |
  10 | 0
 
> stem(test,scale = 10)
 
  The decimal point is 1 digit(s) to the right of the |
 
    4 | 7
    6 |
    8 |
   10 |
   12 | 2
   14 |
   16 |
   18 |
   20 |
   22 |
   24 |
   26 |
   28 |
   30 |
   32 |
   34 |
   36 |
   38 |
   40 |
   42 |
   44 |
   46 |
   48 |
   50 |
   52 |
   54 |
   56 |
   58 |
   60 |
   62 |
   64 |
   66 |
   68 |
   70 |
   72 |
   74 |
   76 |
   78 |
   80 |
   82 |
   84 |
   86 |
   88 |
   90 |
   92 |
   94 |
   96 |
   98 |
  100 | 0
 
> stem(test,scale = 20)
 
  The decimal point is 1 digit(s) to the right of the |
 
    5 | 7
    6 |
    7 |
    8 |
    9 |
   10 |
   11 |
   12 | 2
   13 |
   14 |
   15 |
   16 |
   17 |
   18 |
   19 |
   20 |
   21 |
   22 |
   23 |
   24 |
   25 |
   26 |
   27 |
   28 |
   29 |
   30 |
   31 |
   32 |
   33 |
   34 |
   35 |
   36 |
   37 |
   38 |
   39 |
   40 |
   41 |
   42 |
   43 |
   44 |
   45 |
   46 |
   47 |
   48 |
   49 |
   50 |
   51 |
   52 |
   53 |
   54 |
   55 |
   56 |
   57 |
   58 |
   59 |
   60 |
   61 |
   62 |
   63 |
   64 |
   65 |
   66 |
   67 |
   68 |
   69 |
   70 |
   71 |
   72 |
   73 |
   74 |
   75 |
   76 |
   77 |
   78 |
   79 |
   80 |
   81 |
   82 |
   83 |
   84 |
   85 |
   86 |
   87 |
   88 |
   89 |
   90 |
   91 |
   92 |
   93 |
   94 |
   95 |
   96 |
   97 |
   98 |
   99 |
  100 | 0

你真的懂了R中的stem函数是如何绘制茎叶图的么?的更多相关文章

  1. R中的par()函数的参数

    把R中par()函数的主要参数整理了一下(另外本来还整理了每个参数的帮助文档中文解释,但是太长,就分类之后,整理为图表,excel不便放上来,就放了这些表的截图)

  2. R中的sample函数

    今天介绍一些运算函数,它们的使用很简单,没有什么难度,但是也会用的着. 在医学统计学或者流行病学里的现场调查.样本选择经常会提到一个词:随机抽样.随机抽样是为了保证各比较组之间均衡性的一个很重要的方法 ...

  3. R语言绘制茎叶图

    与直方图相比,茎叶图更能细致的看出数据分布情况! 代码: > x<-c(25, 45, 50, 54, 55, 61, 64, 68, 72, 75, 75,+ 78, 79, 81, 8 ...

  4. R中apply等函数用法[转载]

    转自:https://www.cnblogs.com/nanhao/p/6674063.html 1.apply函数——对矩阵 功能是:Retruns a vector or array or lis ...

  5. 【翻译】R 中的设计模式

    目录 R 中的设计模式 不动点算法 包装器模式 接口模式 柯里化(Currying) 闭包(Closures) 缓存模式 计数器模式 R 中的设计模式 本文翻译自 Design Patterns in ...

  6. 来一轮带注释的demo,彻底搞懂javascript中的replace函数

    javascript这门语言一直就像一位带着面纱的美女,总是看不清,摸不透,一直专注服务器端,也从来没有特别重视过,直到最近几年,javascript越来越重要,越来越通用.最近和前端走的比较近,借此 ...

  7. R中的sub替换函数【转】

    R中的grep.grepl.sub.gsub.regexpr.gregexpr等函数都使用正则表达式的规则进行匹配.默认是egrep的规则,也可以选用Perl语言的规则.在这里,我们以R中的sub函数 ...

  8. python 和 R 中的整数序列

    python 中的 range() 函数是很常用的,R  中相应的函数是 seq(), 其实,R 中的“ :”也能代替 python 中的 range() 函数. 1.生成升序整数序列 python: ...

  9. 你真的懂javascript中的 “this” 吗?

    一.前言: 我们知道 "this" 是javascript语言的一个关键字,在编写javascript代码的时候,经常会见到或者用到它. 但是,有一部分开发朋友,对 "t ...

随机推荐

  1. Compiler Theory(编译原理)、词法/语法/AST/中间代码优化在Webshell检测上的应用

    catalog . 引论 . 构建一个编译器的相关科学 . 程序设计语言基础 . 一个简单的语法制导翻译器 . 简单表达式的翻译器(源代码示例) . 词法分析 . 生成中间代码 . 词法分析器的实现 ...

  2. 08CMS Variable Override Write Arbitrarily WEBSHELL Into Arbitrarily Path

    目录 . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 简单描述这个漏洞 . /include/general.inc.php //本地变 ...

  3. python图形界面(GUI)设计

    不要问我为什么要用 python 来做这种事,我回到“高兴咋地”也不是不可以,总之好奇有没有好的解决方案.逛了一圈下来,总体上来说,python 图形界面有以下几个可行度比较高的解决方案. 1. py ...

  4. Hackerrank Going to the Office

    传送门 Problem Statement Ms.Kox enjoys her job, but she does not like to waste extra time traveling to ...

  5. python增删改查(四)

    ###增删改查 names = ["zhangding","wangxu","wudong","cheng"] #增 n ...

  6. Mysql学习笔记(四)聊聊数据库索引

    小心情(可直接跳到分割线后) 今天心情好些了.一些浓的化不开的坏情绪,也渐渐的在晚上解决掉一个复杂的逻辑问题后,渐渐消散了. 今天中午去吃饭的时候,坤哥漫不经心的说:'我这么多年终于悟出了一个道理,人 ...

  7. iOS - 果冻效果

    具体使用的CADisplayLink和贝塞尔曲线 下载地址:https://github.com/nLoser/CustomAnimation 效果: // // DisplayView.m // C ...

  8. Yocto开发笔记之《网卡配置》(QQ交流群:519230208)

    QQ群:519230208,为避免广告骚扰,申请时请注明 “开发者” 字样 ============================================== # ifconfig -a # ...

  9. 电脑技巧:Win8/Win10无法打开这个应用|无法使用内置管理员账户的完美解决方法

    现在装win10系统的同伴越来越多了,相比于win7,win10在某些设置方面也有些变化,比如我们在使用win8或者win10时,会碰到如图所示的对话框: Windows10/Windows8无法使用 ...

  10. asp.net js 倒计时总秒数量 和 排序

    Edit in JSFiddle JavaScript HTML CSS Result h1 { font-family: "微软雅黑"; font-size: 40px; mar ...