1. 程式人生 > >R語言做條形圖時候,離散變量和連續型變量的區別

R語言做條形圖時候,離散變量和連續型變量的區別

nbsp identity ble present variable () cal 區別 變量

1)條形圖

條形圖或許是最常用圖形,常用來展示分類(different categories on the x-axis)和數值(numeric values on the y-axis)之間的關系。sometimes the bar heights represent counts of cases in the data set, and sometimes they represent values in the data set(有時條形圖高度代表數據集中的頻數(count),有時候代表數據集中的值(values),這個要牢牢的記在心中,否則會產生疑惑).

1.1)以BOD數據框中的數據為例

技術分享圖片

1.2) 當x為(連續型或數字變量):one bar at each possible x value between the minimum and the maximum

ggplot(BOD, aes(x=Time, y=demand)) + geom_bar(stat="identity")

技術分享圖片

1.3) 當x為分類變量時候:having one bar at each actual x value,

# Convert Time to a discrete (categorical) variable with factor()
ggplot(BOD, aes(x=factor(Time), y=demand)) + geom_bar(stat="identity")

技術分享圖片

R語言做條形圖時候,離散變量和連續型變量的區別