今天箱线图

前天那个玫瑰图画出来了, 构建geom_rose的那个函数中的fill = calc(level))出现了问题,改成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()

今天学习箱线图 需要数据data可以微信问我要,这里发不了文件

getwd()
setwd('C:/Users/14327/Desktop/公众号/第四篇')

##加载包
library(ggpubr)

##读取数据
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",##调色
)


p2 <- ggboxplot(data, x = "Treatment", y = "SOC",
          bxp.errorbar=T,
          width = 0.5,
          color = "Treatment",
          palette="aaas",
          orientation = "horizontal"#调整图形方向为水平
)

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")#调整顺序
)
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))#参数add的参数,可设置颜色
Rplot01.png

参考资料:https://eric.netlify.app/2017/11/24/using-a-multivariate-normal-to-draw-a-flower-in-ggplot2/ ,https://www.jianshu.com/p/20eb223be60c
以上就是今天的内容啦,明天准备回家吃排骨,这几天要读文献,接下来几天会发点生态文献,大家劳动节快乐!

微信图片_20210429234543.jpg

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 今天用最近看的一篇Nature Communications的数据试试ggplot2绘图,时间和能力有限,学了一半...
    Karupin99阅读 538评论 0 0
  • From shirinsplayground,非常好的机器学习的文章,保存下来,慢慢学习。 https://shi...
    iColors阅读 1,229评论 0 0
  • 我是黑夜里大雨纷飞的人啊 1 “又到一年六月,有人笑有人哭,有人欢乐有人忧愁,有人惊喜有人失落,有的觉得收获满满有...
    陌忘宇阅读 8,602评论 28 53
  • 信任包括信任自己和信任他人 很多时候,很多事情,失败、遗憾、错过,源于不自信,不信任他人 觉得自己做不成,别人做不...
    吴氵晃阅读 6,225评论 4 8
  • 怎么对待生活,它也会怎么对你 人都是哭着来到这个美丽的人间。每个人从来到尘寰到升入天堂,整个生命的历程都是一本书,...
    静静在等你阅读 5,018评论 1 6