# 1. 直方图不是柱状图

1. 柱状图的X轴表示种类数据，或是时间序列数据，然而直方图的X轴表示连续的变量。
2. 柱状图中，用柱子的高度表示value，而直方图用面积表示value。
3. 柱状图表示各个种类中明确的值的对比，比如不同国籍人口数量的对比；而直方图表示不同变量中值的分布。

# 2. 柱状图

``````
> list.files()

> names(nba)
[1] "Name"                               "Age"
[3] "Team"                               "POS"
[5] "X."                                 "X2013.."
[7] "Ht"                          		  "WT"
[9] "EXP"                                "X1st.Year"
[11] "DOB"                                "School"
[13] "City"                               "State..Province..Territory..Etc..."
[15] "Country"                            "Race"
[17] "HS.Only"

> warriors <- subset(players, Team=="Warriors")

> warriors.o <- warriors[order(warriors\$Ht),]

> par(mar=c(5,10,5,5))

# 因为barplot中必选参数 height必须是数值型，所以要讲char转换到numeric
> myht <- as.numeric(as.character(warriors.o\$Ht))
> barplot(myht, names.arg=warriors.o\$Name, horiz=TRUE, border=NA, las=1, main="Heights of Golden State Warriors")
``````

# 3. 直方图

``````> par(mfrow=c(1,3), mar=c(3,3,3,3))
> hist(myht, main="NBA Player Heights", xlab="inches", breaks=seq(65, 90, 1))
> hist(myht, main="NBA Player Heights", xlab="inches", breaks=seq(65, 90, 2))
> hist(myht, main="NBA Player Heights", xlab="inches", breaks=seq(65, 90, 5))
``````

``````> hist(myht, main="NBA Player Heights", xlab="inches", breaks=c(seq(65, 75, 2), 80, 90))
> hist(myht, main="NBA Player Heights", xlab="inches", breaks=c(65, 75, seq(80, 90, 2)))
> hist(myht, main="NBA Player Heights", xlab="inches", breaks=c(65, seq(70, 80, 1), 90))
``````