前天那個玫瑰圖畫出來了, 構(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
