1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢(xún)
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問(wèn)題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
      如何利用R語(yǔ)言的ggplot2包繪制箱線圖

      小編給大家分享一下如何利用R語(yǔ)言的ggplot2包繪制箱線圖,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!

      創(chuàng)新互聯(lián)建站基于分布式IDC數(shù)據(jù)中心構(gòu)建的平臺(tái)為眾多戶(hù)提供樂(lè)山服務(wù)器托管 四川大帶寬租用 成都機(jī)柜租用 成都服務(wù)器租用。

      一 繪制基本的箱線圖

      載入數(shù)據(jù)及函數(shù)包

      library(ggplot2)library(RColorBrewer)

      dose數(shù)值 變成因子變量

      ToothGrowth$dose <- as.factor(ToothGrowth$dose) head(ToothGrowth) #查看數(shù)據(jù)集   len supp dose1  4.2   VC  0.52 11.5   VC  0.53  7.3   VC  0.54  5.8   VC  0.55  6.4   VC  0.56 10.0   VC  0.5

      1)geom_boxplot繪制基本的箱線圖

      使用ToothGrowth數(shù)據(jù)集,dose變量為分類(lèi)橫坐標(biāo),對(duì)len變量做箱線圖

      ggplot(ToothGrowth, aes(x=dose, y=len)) + geom_boxplot()

      如何利用R語(yǔ)言的ggplot2包繪制箱線圖

      旋轉(zhuǎn)箱線圖方向并設(shè)置notch

      ggplot(ToothGrowth, aes(x=dose, y=len)) + geom_boxplot(notch=TRUE) + coord_flip()

      如何利用R語(yǔ)言的ggplot2包繪制箱線圖

      2)修改異常點(diǎn)的屬性

       設(shè)置outlier的 color, shape and size 

      ggplot(ToothGrowth, aes(x=dose, y=len)) + geom_boxplot(outlier.colour="red", outlier.shape=18,outlier.size=4)

      如何利用R語(yǔ)言的ggplot2包繪制箱線圖

      此外, outlier.fill:離群點(diǎn)的填充色;outlier.alpha:離群點(diǎn)的透明度

      3)選擇變量,設(shè)定順序

      ggplot(ToothGrowth, aes(x=dose, y=len)) + geom_boxplot() + stat_summary(fun.y=mean, geom="point", shape=23, size=4, col = "red") +  #添加均值scale_x_discrete(limits=c("2", "0.5")) #選擇變量,更改順序

      如何利用R語(yǔ)言的ggplot2包繪制箱線圖

      4)添加最大值和最小值的兩條須線

      ggplot(ToothGrowth, aes(x=dose, y=len)) + stat_boxplot(geom = "errorbar",width=0.15) + #添加虛線geom_boxplot()

      如何利用R語(yǔ)言的ggplot2包繪制箱線圖

      5)箱線圖添加點(diǎn)

      geom_point函數(shù),向箱線圖中添加點(diǎn);

      ggplot(ToothGrowth, aes(x=dose, y=len)) + geom_boxplot() + geom_dotplot(binaxis='y', stackdir='center', dotsize=1, binwidth = 1)

      如何利用R語(yǔ)言的ggplot2包繪制箱線圖

      geom_jitter()函數(shù)是geom_point(position = "jitter")的包裝,binaxis="y"是指沿著y軸進(jìn)行分箱;

      ggplot(ToothGrowth, aes(x=dose, y=len)) + geom_boxplot() + geom_jitter(shape=16, position=position_jitter(0.2))

      如何利用R語(yǔ)言的ggplot2包繪制箱線圖

      二 顏色設(shè)置

      aes(color=)函數(shù)為每個(gè)箱線圖設(shè)置一個(gè)顏色,劃分箱線圖之后,可以使用scale_color_*()函數(shù)自定義顏色。

      1)分組更改箱線的顏色

      p<-ggplot(ToothGrowth, aes(x=dose, y=len, color=dose)) + geom_boxplot()p

      如何利用R語(yǔ)言的ggplot2包繪制箱線圖

      自定義顏色方案

      # Use custom color palettesp+scale_color_manual(values=c("#999999", "#E69F00", "skyblue"))# Use brewer color palettesp+scale_color_brewer(palette="Set3")+ theme_classic()# Use grey scalep + scale_color_grey() + theme_classic()

      如何利用R語(yǔ)言的ggplot2包繪制箱線圖

      2)更改箱子填充顏色

      fill 填充色 ; color 箱線的外框顏色

      #單組 設(shè)置顏色

      ggplot(ToothGrowth, aes(x=dose, y=len)) + geom_boxplot(fill='#A4A4A4', color="black")+ theme_classic()

      #分組 設(shè)置顏色 , 自定義顏色設(shè)置方案同上

      ggplot(ToothGrowth, aes(x=dose, y=len, fill=dose)) + geom_boxplot() + scale_fill_brewer(palette="Dark2") + theme_classic()

      如何利用R語(yǔ)言的ggplot2包繪制箱線圖

      三 圖例,標(biāo)題設(shè)置

      1)設(shè)置legeng

      Legend是對(duì)箱線圖的解釋性描述,默認(rèn)的位置是在畫(huà)布的右側(cè)中間位置,可以通過(guò)theme()函數(shù)修改Legend的位置

      p + theme(legend.position="top")p + theme(legend.position="bottom")p + theme(legend.position="none") # Remove legend

      如何利用R語(yǔ)言的ggplot2包繪制箱線圖

      2)labs設(shè)置標(biāo)題及坐標(biāo)標(biāo)簽

      p+theme(legend.position="bottom") + labs(title="Plot of length  per dose",x="Dose (mg)", y = "Length")

      如何利用R語(yǔ)言的ggplot2包繪制箱線圖

      3)其他theme詳細(xì)設(shè)置可參考ggplot2-theme(主題)以及ggplot2-圖形微調(diào)(1)

      四 箱線圖匯總展示

      ggplot(ToothGrowth, aes(x=dose, y=len, fill=dose)) +   stat_boxplot(geom = "errorbar",width=0.15)+  geom_boxplot()+  geom_dotplot(binaxis='y', stackdir='center', dotsize=0.5, binwidth = 1)+  labs(title="Plot of length  per dose",x="Dose (mg)", y = "Length")+  scale_fill_manual(values=c("#999999", "#E69F00", "#56B4E9")) +   theme(legend.position="none")+  theme_minimal()

      如何利用R語(yǔ)言的ggplot2包繪制箱線圖

      看完了這篇文章,相信你對(duì)“如何利用R語(yǔ)言的ggplot2包繪制箱線圖”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!


      新聞名稱(chēng):如何利用R語(yǔ)言的ggplot2包繪制箱線圖
      網(wǎng)頁(yè)網(wǎng)址:http://www.ef60e0e.cn/article/pcejoo.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        松滋市| 盱眙县| 华亭县| 宾阳县| 蚌埠市| 安庆市| 金溪县| 交城县| 墨脱县| 运城市| 邢台市| 方城县| 平南县| 东宁县| 灵山县| 土默特右旗| 五台县| 淮南市| 牡丹江市| 韶关市| 江城| 南投县| 民丰县| 香港| 新民市| 兖州市| 自贡市| 疏勒县| 彰化市| 贺兰县| 定西市| 会东县| 姜堰市| 农安县| 潢川县| 凯里市| 广宁县| 祁门县| 留坝县| 泗洪县| 河源市|