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)
相关推荐
全栈开发圈3 天前
干货分享|如何从0到1掌握R语言数据分析
开发语言·数据分析·r语言
小杜的生信筆記6 天前
基于R语言,“上百种机器学习模型”学习教程 | Mime包
开发语言·学习·机器学习·r语言·sci
在打豆豆的小潘学长7 天前
【R语言】多样本单细胞分析_SCTransform+Harmony方案(2)
开发语言·r语言
TS的美梦7 天前
ROGUE: 【张院士团队R包】一种基于熵的用于评估单细胞群体纯度的度量标准
开发语言·r语言
weixin_493202639 天前
R语言代码加密(1)
r语言
Tiger Z9 天前
《R for Data Science (2e)》免费中文翻译 (第3章) --- Data transformation(2)
r语言·数据科学·中文翻译
星石传说11 天前
使用R将nc文件转换为asc文件或者tif文件
r语言·生信
Mister Leon12 天前
机器学习Adaboost算法----SAMME算法和SAMME.R算法
算法·机器学习·r语言
Tiger Z12 天前
R 语言科研绘图第 67 期 --- 箱线图-显著性
r语言·论文·科研·绘图·研究生
惊岁晚12 天前
【实践记录】github仓库的更新
算法·容器·r语言·github