當前位置:外匯行情大全網 - 信用卡套現 - 如何用r語言繪制多變量散點圖

如何用r語言繪制多變量散點圖

給妳壹些代碼,妳慢慢研究:

install.packages('ggplot2')

library(ggplot2)

ggplot(a)+geom_bar(aes(x1,y,fill/col=x1/x2),position='dodge',stat='summary',fun='sum'/'mean')條形圖+theme(text = element_text(family='Kai'))

ggplot(a)+geom_boxplot(aes(x1,y,col=x1/x2))箱線圖

ggplot(a)+geom_point(aes(x1,y,col=x1/x2),position=position_jitter(width=0.04))散點圖

1+geom_point(aes(x1,y,col=x1/x2),stat='summary',fun='sum'/'mean')+散點

2+geom_line(aes(x1,y,group=1/x2,col=x1/x2),stat='summary',fun='sum'/'mean')+折線

3+geom_errorbar(aes(x=x1,ymin=y-se,ymax=y+se,col=x1/x2),position=position_dodge(0.9),width=0.2)+誤差棒

4+geom_text(aes(x1,y,label=marker,col=x1/x2),position=position_dodge(0.9)vjust=2或y+2)+顯著字母

ggplot(a,aes(x1,y,fill/col=x1/x2))+geom_bar(position='dodge',stat='summary',fun='sum'/'mean')+geom_errorbar(aes(ymin=y-se,ymax=y+se),position=position_dodge(0.9),width=0.2)+geom_text(aes(label=marker),position=position_dodge(0.9),vjust=-2)條形圖+誤差棒+顯著字母(坐標寫壹次即可)

ggplot(a,aes(x1,y,col=x1/x2))+geom_point(position=position_jitter(width=0.04),stat='summary',fun='sum'/'mean')+geom_line(aes(group=1/x2),stat='summary',fun='sum'/'mean')+geom_errorbar(aes(ymin=y-se,ymax=y+se),position=position_dodge(0.9),width=0.2)+geom_text(aes(label=marker),position=position_dodge(0.9),vjust=-2)散點圖+折線+誤差棒+顯著字母(坐標寫壹次即可)

+geom_density(aes(y=liqi))密度圖(1個數值型)

+geom_area(aes(x=tan,y=liqi))區域圖(2個數值型)

+geom_smooth(aes(x=tan,y=liqi,group/col=chong),formula=y~x,method='lm',se=F)擬合圖,分組/線條顏色(2個數值型)

+facet_wrap(~riqi,ncol/nrow=2,labeller='label_both/value')分面圖,每行或每列分面數,分面標題

+xlab('自變量1(單位)')+ylab('因變量(單位)')+scale_fill_discrete(name='自變量2')更改軸和圖例名稱+coord_cartesian(ylim= c(0,80))限定軸範圍

(fill=x1/x2,有此即可變色)+scale_fill_manual(values = c('grey70', 'grey50', 'grey30'))改變條形填充顏色(顏色數量=分組數量)

(col=x1/x2,有此即可變色)+scale_color_manual(values = c('red', 'orange', 'yellow'))改變顏色(顏色數量=分組數量)

  • 上一篇:四信用卡無損倒卡技巧
  • 下一篇:閃電貸1000逾期30天以上有什麽嚴重後果?
  • copyright 2024外匯行情大全網