ggplot2绘制概率密度图
以下绘图以Weibull分布(韦伯分布、威布尔分布)为例
关于Weibull分布(韦伯分布、威布尔分布),请参考本人博客http://www.cnblogs.com/wwxbi/p/6141501.html
- library(ggplot2)
- # 这里的d和y都有大小顺序
- d<- seq(0, 5, length.out=10000)
- y<-dweibull(d, shape=5, scale=1, log = FALSE)
- df<-data.frame(x=d,y)
- ggplot(df,aes(x=d,y))+
- geom_line(colour="green")+
- ggtitle("Weibull distribution \n 概率密度图")
- # 这里的h没有大小顺序
- h <- rweibull(100000, shape=5, scale=1)
- ggplot(NULL,aes(x=h))+
- geom_histogram(binwidth = 0.01,fill="white",colour="red")+
- ggtitle("Weibull distribution \n 直方图")
- ggplot(NULL,aes(x=h))+
- geom_density(colour="green")+
- ggtitle("Weibull distribution \n 概率密度图")
- ggplot(NULL,aes(x=h))+
- geom_line(stat="density",colour="green")+
- ggtitle("Weibull distribution \n 概率密度图")
- library(sqldf)
- library(ggplot2)
- d<- seq(0, 5, length.out=10000)
- df1<-data.frame(num=seq(0,5,length=10000),groupID="λ=1,k=0.5",rw=dweibull(d, scale=1,shape=0.5 ))
- df2<-data.frame(num=seq(0,5,length=10000),groupID="λ=1,k=1",rw=dweibull(d, scale=1,shape=1 ))
- df3<-data.frame(num=seq(0,5,length=10000),groupID="λ=1,k=1.5",rw=dweibull(d, scale=1,shape=1.5 ))
- df4<-data.frame(num=seq(0,5,length=10000),groupID="λ=1,k=5",rw=dweibull(d, scale=1,shape=5 ))
- df5<-sqldf("
- select num,groupID,rw from df1
- union all
- select num,groupID,rw from df2
- union all
- select num,groupID,rw from df3
- union all
- select num,groupID,rw from df4 ")
- df<-subset(df5, rw <2 )
- ggplot(df,aes(x=num,y=rw,group=factor(groupID),colour=factor(groupID)))+
- geom_line()+
- ggtitle("Weibull distribution \n 概率密度图")
- library(sqldf)
- library(ggplot2)
- df2<-data.frame(num=seq(0,5,length=10000),groupID="λ=1,k=1",rw=rweibull(10000, scale=1,shape=1 ))
- df3<-data.frame(num=seq(0,5,length=10000),groupID="λ=1,k=1.5",rw=rweibull(10000, scale=1,shape=1.5 ))
- df4<-data.frame(num=seq(0,5,length=10000),groupID="λ=1,k=5",rw=rweibull(10000, scale=1,shape=5 ))
- df<-sqldf("
- select num,groupID,rw from df2
- union all
- select num,groupID,rw from df3
- union all
- select num,groupID,rw from df4 ")
- ggplot(df,aes(x=rw,group=factor(groupID),colour=factor(groupID)))+
- geom_density()+
- ggtitle("Weibull distribution \n 概率密度图")
- library(sqldf)
- library(ggplot2)
- d<- seq(0, 5, length.out=10000)
- df1<-data.frame(num=seq(0,5,length=10000),groupID="λ=0.5,k=1",rw=dweibull(d, scale=0.5,shape=1 ))
- df2<-data.frame(num=seq(0,5,length=10000),groupID="λ=1,k=1",rw=dweibull(d, scale=1,shape=1 ))
- df3<-data.frame(num=seq(0,5,length=10000),groupID="λ=1.5,k=1",rw=dweibull(d, scale=1.5,shape=1 ))
- df4<-data.frame(num=seq(0,5,length=10000),groupID="λ=3,k=1",rw=dweibull(d, scale=3,shape=1 ))
- df5<-sqldf("
- select num,groupID,rw from df1
- union all
- select num,groupID,rw from df2
- union all
- select num,groupID,rw from df3
- union all
- select num,groupID,rw from df4 ")
- df<-df5
- ggplot(df,aes(x=num,y=rw,group=factor(groupID),colour=factor(groupID)))+
- geom_line()+
- ggtitle("Weibull distribution \n 概率密度图")
ggplot2绘制概率密度图的更多相关文章
- ggplot2绘制多图
参考链接:http://www.cnblogs.com/nxld/p/6065237.html ggplot2.multiplot是一个易于使用的功能,将多个图形在同一页面上使用R统计软件和GGPLO ...
- R绘图 第六篇:绘制线图(ggplot2)
线图是由折线构成的图形,线图是把散点从左向右用直线连接起来而构成的图形,在以时间序列为x轴的线图中,可以看到数据增长的趋势. geom_line(mapping = NULL, data = NULL ...
- R-forestplot包| HR结果绘制森林图
本文首发于“生信补给站”微信公众号,https://mp.weixin.qq.com/s/2W1W-8JKTM4S4nml3VF51w 更多关于R语言,ggplot2绘图,生信分析的内容,敬请关注小号 ...
- R绘制韦恩图 | Venn图
解决方案有好几种: 网页版,无脑绘图,就是麻烦,没有写代码方便 极简版,gplots::venn 文艺版,venneuler,不好安装rJava,参见Y叔 酷炫版,VennDiagram 特别注意: ...
- 用canvas绘制折线图
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- php中用GD绘制折线图
php中用GD绘制折线图,代码如下: Class Chart{ private $image; // 定义图像 private $title; // 定义标题 private $ydata; // 定 ...
- 使用Canvas绘制背景图
原文 http://www.imququ.com/post/use-canvas-as-background-image.html 最近iCloud Web的Beta版换了UI,整体风格变得和iOS ...
- Excel应该这么玩——7、我是预言家:绘制趋势图
让我们先看一个场景:你是公司销售部的员工,你手里有公司最近几年的销售额相关的数据,经理希望你预测下个月的销售额.盯着一堆数据,你或许会想到画一张XY坐标图,然后将每个月份的销售额标定为一个坐标.但是下 ...
- 使用Excel 2007绘制甘特图
本文将教大家如何使用Excel 2007制作甘特图.Excel并未提供甘特图类型,但还是可以绘制甘特图的,方法就是通过对堆积条形图类型进行自定义,使之显示任务.任务工期和层次结构. 下面的过程可帮助创 ...
随机推荐
- QT QGraphicsProxyWidget对象可选择或移动的一些tricks
我在QT图形视图框架中使用QGraphicsProxyWidget嵌入widget,但是无法使其和其它的QGraphicsItem一样可以选择或移动,使用如下语句无效: C++ Code 1234 ...
- javascript消除字符串两边空格的两种方式,面向对象和函数式编程。python oop在调用时候的优点
主要是javascript中消除字符串空格,比较两种方式的不同 //面向对象,消除字符串两边空格 String.prototype.trim = function() { return this.re ...
- Core Java笔记
前言 一·基础知识 二·定义,关键字和类型 三·表达式和控制流 四·数组 五·对象和类 六·高级语言特性 七·异常 八·图形用户接口 九·AWT(Abstract Window Toolkit) 事件 ...
- [AX]AX2012 R2 采购订单的“Request change”
在采购订单List或者Detail窗口的操作面板上有一个叫做“Request change”的按钮,如果这个按钮是激活的,采购订单不能直接编辑,而必须先使用这个按钮请求修改后,采购订单才能进入编辑状态 ...
- 屏蔽win10中文输入法
Windows 10自带的默认输入法,是通过Shift键来切换中/英文,这样为玩一些不需要打字,却需要使用Shift键的游戏带来了不便,比如,在进行游戏的时候,按下Shift键后,再按跳跃.射击等键, ...
- pycharm 激活
方法1: (1)更新**hosts**文件 [hosts文件百度云下载地址](https://pan.baidu.com/s/1o9ZujxS) **hosts**文件在windows中的地址为: C ...
- An internal error occurred during: "Launching xxx on WebLogic10.x".
An internal error occurred during: "Launching xxx on WebLogic10.x". java.lang.NullPointerE ...
- 【RF库Collections测试】Reverse List
Name:Reverse ListSource:Collections <test library>Arguments:[ list_ ]Reverses the given list i ...
- 使用java连接数据库以后显示“ Establishing SSL connection without server's identity verification is not recommended”的警告如何解决
今天写了一段查询数据库的操作,如下 package MySQL; import java.sql.*; public class MySQL { //JDBC驱动名以及数据库URL static fi ...
- 敏捷开发中的Scrum流程和术语【转】
任何人力流程都离不开人来执行,所以在讲解Scrum流程之前,有必要先把Scrum中的角色讲一下. 一天,一头猪和一只鸡在路上散步,鸡看了一下猪说,“嗨,我们合伙开一家餐馆怎么样?”,猪回头看了一下鸡说 ...