? ? ? ? ? ? ? ? ? ? ? ? ? ? ?R 語言繪制簡(jiǎn)單條形圖
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?參考書籍:R數(shù)據(jù)可視化手冊(cè)
1、使用barplot()函數(shù)繪制簡(jiǎn)單條形圖
library(datasets)#數(shù)據(jù)來源
library(ggplot2)
barplot(BOD$demand,names.arg= BOD$Time)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?數(shù)據(jù)展示

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?繪圖結(jié)果

2、使用ggplot()函數(shù)繪制簡(jiǎn)單條形圖
library(datasets)
library(ggplot2)
ggplot(BOD,aes(x=Time,y=demand))+geom_bar(stat="identity")
ggplot(BOD,aes(x=factor(Time),y=demand))+geom_bar(stat="identity")
ggplot(BOD,aes(x=Time,y=demand))+geom_bar(stat="identity")+geom_bar(stat="identity",fill="lightblue",colour="black")
#fill修改填充色顏色,colour修改邊框顏色
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Time是數(shù)值型(連續(xù)型)變量

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?factor()函數(shù) 將Time轉(zhuǎn)化為離散型變量(分類變量)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 美化條形圖

3、繪制簇狀條形圖
?
library(gcookbook)
#library(RColorBrewer)
#其中cultivar,data是分類變量,weight是數(shù)值。
ggplot(cabbage_exp,aes(x=Date,y=Weight,fill=Cultivar))+geom_bar(position= "dodge",stat ="identity" )
?#添加colour修改為黑色邊框,使用scale_fill_brewer()或scale_fill_manual()函數(shù)
P<-ggplot(cabbage_exp,aes(x=Date,y=Weight,fill=Cultivar))+geom_bar(position= "dodge",stat ="identity",colour="black" )
P+scale_fill_brewer(palette="Greens")
P+scale_fill_brewer(palette=1)
P+scale_fill_brewer(palette="Set2")
P+scale_fill_manual(values=c("lightpink1","lightsalmon"))
P+scale_fill_manual(values=c("419","424"))
P+scale_fill_manual(values=c("#FFAEB9","#FFA07A"))
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? palette="Greens

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "palette=2

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?palette="Set2"

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"lightpink1","lightsalmon"

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "419","424"

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "#FFAEB9","#FFA07A"
