R可视化:另类的箱线图

介绍

方格状态的箱线图

加载R包

{r} 复制代码
knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)
library(patternplot)
library(png)
library(ggplot2)
library(gridExtra)

rm(list = ls())
options(stringsAsFactors = F)

导入数据

{r, 复制代码
data <- read.csv(system.file("extdata", "fruits.csv", package = "patternplot"))

准备数据

{r, 复制代码
group <- data$Fruit
y <- data$Weight
x <- data$Store

pattern.type <- c('nwlines', 'blank', 'waves')
pattern.color <- c('black','black', 'black')
background.color <- c('white','gray80', 'white')
frame.color <- c('black', 'black', 'black')
pattern.line.size <- c(6, 1,6)
density <- c(6, 1, 8)

画图

{r, 复制代码
box1 <- patternboxplot(
  data, x, y, group = group,
  pattern.type = pattern.type,
  pattern.line.size = pattern.line.size, 
  label.size = 3, 
  pattern.color = pattern.color, 
  background.color = background.color,
  frame.color = frame.color,
  density = density,  
  legend.h = 2, 
  legend.x.pos = 1.075, 
  legend.y.pos = 0.499, 
  legend.pixel = 10,
  legend.w = 0.18, 
  legend.label = c("Orange","Strawberry","Watermelon")) +
  ggtitle('(A) Boxplot with Black and White Patterns')

pattern.color <- c('black','white', 'grey20')
background.color <- c('gold','lightpink', 'lightgreen')

box2 <- patternboxplot(
  data, x, y, group = group,
  pattern.type = pattern.type,
  pattern.line.size = pattern.line.size, 
  label.size = 3,
  pattern.color = pattern.color, 
  background.color = background.color,
  frame.color = frame.color, 
  density = density,
  legend.h = 2, 
  legend.x.pos = 1.075, 
  legend.y.pos = 0.499, 
  legend.pixel = 10,
  legend.w = 0.18, 
  legend.label = c("Orange","Strawberry","Watermelon")) +
  ggtitle('(B) Boxplot with Colors and Patterns')

grid.arrange(box1, box2, nrow = 1)
相关推荐
lishaoan772 天前
实验设计与分析(第6版,Montgomery著,傅珏生译) 第10章拟合回归模型10.9节思考题10.12 R语言解题
回归·r语言·线性回归·残差分析·实验设计与数据分析·回归显著性
南瓜胖胖2 天前
【R语言编程绘图-mlbench】
开发语言·机器学习·r语言
天桥下的卖艺者2 天前
R语言使用随机过采样(Random Oversampling)平衡数据集
开发语言·r语言
Biomamba生信基地3 天前
R语言基础| 创建数据集
开发语言·r语言·生信·医药
lishaoan773 天前
实验设计与分析(第6版,Montgomery)第5章析因设计引导5.7节思考题5.19 R语言解题
r语言·方差分析·实验设计与分析·残差分析·正态假设·交互作用
weixin_493202634 天前
R语言错误处理方法大全
开发语言·r语言
lishaoan774 天前
实验设计与分析(第6版,Montgomery)第4章随机化区组,拉丁方, 及有关设计4.5节思考题4.1~4.4 R语言解题
r语言·统计分析·方差分析·实验设计与分析·随机化区组
lishaoan774 天前
实验设计与分析(第6版,Montgomery)第5章析因设计引导5.7节思考题5.5 R语言解题
r语言·方差分析·实验设计与分析·残差分析·正态性假设·交互作用·析因实验
lishaoan775 天前
实验设计与分析(第6版,Montgomery)第5章析因设计引导5.7节思考题5.2 R语言解题
r语言·统计分析·方差分析·实验设计与分析·残差分析·交互作用·析因实验
南瓜胖胖5 天前
【R语言编程绘图-plotly】
开发语言·plotly·r语言