ggplot基礎語句
折線圖
柱形圖ggplot(data,aes(x=
,y=,colour=
,group=))
+ geom_line(size=1)
+ labs(x=
'',y=
'',title='')
+# 標題居中
theme(plot.title = element_text(hjust =
0.5)
)
ggplot一頁多圖ggplot(data,aes(x=
,y=))+
# 顯示實際頻數
geom_bar(position =
"dodge"
,stat =
"identity"
,width =
0.5,fill=
'lightblue3')+
# 排序用的,可以把柱形圖排序
scale_x_discrete(limits=factor(var))+
# 加文字數字
geom_text(aes(x=
,y=,label=))
# 可以變成橫向柱形圖,豎著的不用加這個語句
coord_flip()+
# 調整文字大小
theme(axis.text.x =element_text(size=9)
, axis.text.y=element_text(size=9)
)
點的形狀用aes(shape=var)# 方法一:簡單拼接
library(gridextra)
grid.arrange(p1,p2,nrow=1)
# 方法二:按變數來分
facet_wrap(
~var)
日期中文改英文:
sys.setlocale(「lc_time」, 「english」)
R正態分佈 ggplot
randnorm rnorm 3000 rnorm 3000 產生3000個正太分布數 randdensity dnorm randnorm dnorm randnorm 求其密度函式值 ggplot data.frame x randnorm,y randdensity aes x x,y y g...
r語言匯入ggplot2 R中的ggplot2包
qplot 函式是乙個快速作圖函式 用資料diamands head diamonds carat cut color clarity depth table price 0.23 ideal e si2 61.5 55 326 0.21 premium e si1 59.8 61 326 0.23...
R語言ggplot包之資料分布彙總
我們經常想觀察一批資料的分布形態,直方圖 密度圖 箱線圖 小提琴圖和點圖等都是很好的實現形式。在此,我們簡略介紹直方圖 密度圖和箱線圖,這種三種圖形對我們來說更為常用。很多人沒搞清楚條形圖和直方圖之間的區別。條形圖主要用於展示分類資料,即名義資料,各組分開而立。而直方圖多用於展示數值型資料,各組相依...