今天箱線圖

前天那個玫瑰圖畫出來了, 構(gòu)建geom_rose的那個函數(shù)中的fill = calc(level))出現(xiàn)了問題,改成stat()就好了,當然把fill = calc(level))去掉的話也可以,但是花就變成了黑色。

代碼如下,各位可以試一下

library(raster)##沒安裝的話安裝一下install.package('raster')
library(ggplot2)##同上
knitr::opts_chunk$set(dev = "svg")
library(tidyverse)
p <- ggplot() + 
  coord_equal(1, c(-4, 2), c(-7, 3)) +
  geom_curve(aes(x = -1, y = -7, xend = 0, yend = 0), 
             ncp = 1000, curvature = -0.3, size = 1, 
             color = "olivedrab3")
p
geom_leaf <- function(x, xend, f, xoffset = 0, yoffset = 0, 
                      xflip = 1, yflip = 1, ...) {
  
  .x <- seq(x, xend, length.out = 100)
  .y <- f(.x)
  
  df <- tibble(x = c(.x, .y), y = c(.y, .x))
  df$x <- xflip * df$x + xoffset
  df$y <- yflip * df$y + yoffset
  
  geom_polygon(aes(x = x, y = y), data = df, ...)
}
f <- function(x) x^2 / 2

p <- p +
  geom_leaf(0, 2, f, -1.6, -4.5, 1, 
            fill = "olivedrab3", color = "palegreen") +
  geom_leaf(0, 2, f, -1.6, -5,  -1, 
            fill = "olivedrab3", color = "palegreen")
p
geom_rose <- function(n, mean = c(0, 0), ...) {
  
  .x <- mvtnorm::rmvnorm(n, mean)
  df <- tibble(x = .x[, 1], y = .x[, 2])
  
  list(
    stat_density_2d(
      aes(x = x, y = y, fill = stat(level)), data = df, ###去掉fill=stat(level)花會變成黑色哈哈哈
      geom = "polygon", show.legend = FALSE, color = "grey80"),
    scale_fill_gradient2(...)
  )
}
p +
  geom_rose(1000, mean = c(0, 0), 
            low = "red", mid = "purple", high = "pink",
            midpoint = 0.075) +
  theme_void()

今天學習箱線圖 需要數(shù)據(jù)data可以微信問我要,這里發(fā)不了文件

getwd()
setwd('C:/Users/14327/Desktop/公眾號/第四篇')

##加載包
library(ggpubr)

##讀取數(shù)據(jù)
data <- read.csv('data.csv')
head(data)
微信圖片_20210429232704.png

畫圖

attach(data)

p1 <- ggboxplot(data, x = "Treatment", y = "SOC",
          bxp.errorbar=T,#顯示誤差條
          width = 0.5,#箱體的寬度
          color = "Treatment", #分組
          palette="aaas",##調(diào)色
)


p2 <- ggboxplot(data, x = "Treatment", y = "SOC",
          bxp.errorbar=T,
          width = 0.5,
          color = "Treatment",
          palette="aaas",
          orientation = "horizontal"#調(diào)整圖形方向為水平
)

p3 <- ggboxplot(data, x = "Treatment", y = "SOC",
          bxp.errorbar=T,
          width = 0.5,
          color = "Treatment",
          palette="aaas",
          notch = TRUE,#添加缺口,
          order = c("DD","CC","BB","AA")#調(diào)整順序
)
p4 <- ggboxplot(data, x = "Treatment", y = "SOC",
          bxp.errorbar=T,
          width = 0.5,
          color = "Treatment",
          select = c("DD")#選擇特定的處理來畫圖    
)
###拼接上面的圖
library(patchwork)

pp <- p1+p2+p3+p4
pp
Rplot.png

添加散點

###添加散點
ggboxplot(data, x = "Treatment", y = "SOC",
          width = 0.5,
          add = "jitter",#添加圖形元素
          add.params=list(color = "Treatment",size=0.8, shape = 23))#參數(shù)add的參數(shù),可設置顏色
Rplot01.png

參考資料:https://eric.netlify.app/2017/11/24/using-a-multivariate-normal-to-draw-a-flower-in-ggplot2/ ,http://www.itdecent.cn/p/20eb223be60c
以上就是今天的內(nèi)容啦,明天準備回家吃排骨,這幾天要讀文獻,接下來幾天會發(fā)點生態(tài)文獻,大家勞動節(jié)快樂!

微信圖片_20210429234543.jpg

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • 今天用最近看的一篇Nature Communications的數(shù)據(jù)試試ggplot2繪圖,時間和能力有限,學了一半...
    Karupin99閱讀 861評論 0 0
  • From shirinsplayground,非常好的機器學習的文章,保存下來,慢慢學習。 https://shi...
    iColors閱讀 1,332評論 0 0
  • 我是黑夜里大雨紛飛的人啊 1 “又到一年六月,有人笑有人哭,有人歡樂有人憂愁,有人驚喜有人失落,有的覺得收獲滿滿有...
    陌忘宇閱讀 8,834評論 28 54
  • 信任包括信任自己和信任他人 很多時候,很多事情,失敗、遺憾、錯過,源于不自信,不信任他人 覺得自己做不成,別人做不...
    吳氵晃閱讀 6,364評論 4 8
  • 怎么對待生活,它也會怎么對你 人都是哭著來到這個美麗的人間。每個人從來到塵寰到升入天堂,整個生命的歷程都是一本書,...
    靜靜在等你閱讀 5,297評論 1 6

友情鏈接更多精彩內(nèi)容