美文网首页
Data Science with R in 4 Weeks -

Data Science with R in 4 Weeks -

作者: 慢思考快思考 | 来源:发表于2016-01-13 20:35 被阅读29次

Week 1 -Day 2

前面我们做了简单的数据分析,接下来我们看一下,怎么把这些数据转换成更直观的的图标的形式。毕竟,data scientist的工作之一就是要communicate insights from data analysis。图表是非常有效的一种形式。

boxplot

首先需要安装ggplot2 这个package

install.packages("ggplot2")

library("ggplot2")

boxplot(z$new_column, col="blue")

公牛队最佳胜率是0.88, 最差的胜率是0.18. 胜率的中位数是0.5

Histogram

从图中来看,胜率主要集中在0.4~0.6之间。如果希望能看到更清晰的颗粒度,我么可以把bar break成更小的间隔

hist(z$new_column, col="green", breaks = 15)

可以自己在图中标注想要的线。例如:

> boxplot(z$new_column, col="blue")

> abline(h=0.78)

再比如

hist(z$new_column, col="green", breaks = 15)

> abline(v = 0.5, lwd = 2)

hist(z$new_column, col="green", breaks = 15)

> abline(v = 0.5, lwd = 2)

如果想按照年份输出呢?——也就是按照时间序列输出

用barplot

先作图

bp <- barplot(mydata$new_column, col="wheat", main ="Chicago Bulls Historical Winning Rate", names.arg =mydata$year)

然后label 各个bar的value

text(bp, mydata$new_column,  labels = round(mydata$new_column, 2), col="black",cex =0.8,  pos =3, offset = 0.1)

this is a very helpful article.

http://www.talkstats.com/archive/index.php/t-24754.html?s=59e14b595125d3fb8910e0e6ee80a585

yourgraph<-barplot( blah blah blah....)

# use text to add freq on the top of the bars

text(yourgraph, d.f$freq, labels=d.f$freq)

http://www.ats.ucla.edu/stat/r/faq/barplotplus.htm

相关文章

网友评论

      本文标题:Data Science with R in 4 Weeks -

      本文链接:https://www.haomeiwen.com/subject/lcqshttx.html