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)
相关推荐
dongf201911 小时前
R语言朴素贝叶斯算法---iris数据集
开发语言·算法·数据分析·r语言
All_Will_Be_Fine噻12 小时前
重建R环境
开发语言·r语言
梦想的初衷~12 小时前
基于R语言APSIM模型高级应用及批量模拟
r语言·apsim·作物生长模型·农业模拟·气象数据处理·土壤水分平衡
dongf201913 小时前
R 语言 逻辑斯蒂回归
开发语言·数据分析·回归·r语言
dongf20193 天前
R 语言 Apriori 关联规则算法
数据分析·r语言·关联规则
dongf20193 天前
R语言决策树剪枝----泰坦尼克数据集
决策树·r语言·剪枝
dongf20193 天前
R语言分类决策数算法----iris数据集
分类·数据分析·r语言
dongf20193 天前
R语言决策树----mtcars数据集
决策树·r语言
稷下元歌3 天前
七天学会plc加机器视觉之AI 接入 外设模块开发全详细操作文档(全程配套视频按文档实操)
python·sql·qt·贪心算法·r语言·wpf·时序数据库
dongf20193 天前
R 语言随机森林算法
算法·随机森林·r语言