当前位置: 首页 > news >正文

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)

导入数据

data <- read.csv(system.file("extdata", "monthlyexp.csv", package="patternplot"))

准备数据

data <- data[which(data$Location == 'City 1'), ]
x <- factor(data$Type, c('Housing', 'Food', 'Childcare'))
y <- data$Amount
pattern.type <- c('hdashes', 'blank', 'crosshatch')
pattern.color <- c('black', 'black', 'black')
background.color <- c('white','white', 'white')
density <- c(20, 20, 10)

画图

barp1 <- patternbar(data, x, y,group = NULL,ylab = 'Monthly Expenses, Dollars', pattern.type = pattern.type, hjust=0.5,pattern.color = pattern.color, background.color = background.color,pattern.line.size = c(5.5, 1, 4),frame.color = c('black', 'black', 'black'), density = density) + scale_y_continuous(limits = c(0, 2800)) +ggtitle('(A) Black and White with Patterns')pattern.color <- c('black','white', 'grey20')
background.color <- c('lightgreen','lightgreen', 'lightgreen')
barp2 <- patternbar(data, x, y, group = NULL,ylab = 'Monthly Expenses, Dollars', pattern.type = pattern.type, hjust=0.5,pattern.color = pattern.color, background.color = background.color,pattern.line.size = c(5.5, 1, 4),frame.color = c('black', 'black', 'black'), density = density) +scale_y_continuous(limits = c(0, 2800)) +ggtitle('(B) Colors with Patterns')grid.arrange(barp1,barp2,  nrow = 1)

在这里插入图片描述

http://www.lryc.cn/news/359284.html

相关文章:

  • Docker的数据管理(数据卷+数据卷容器)
  • 字符串-至多包含K种字符的子串中最长子串(mid)
  • Docker从安装开始精通
  • MFC:初步理解序列化与反序列化(含代码实现)
  • python程序控制结构
  • 【GD32】04 - Timer定时器
  • Golang | Leetcode Golang题解之第123题买卖股票的最佳时机III
  • Leetcode2028. 找出缺失的观测数据
  • 如何在CentOS中合理划分磁盘空间以优化系统性能
  • 算法(十一)贪婪算法
  • Rust之函数式语言特性:迭代器和闭包(一):概述
  • 配置资源管理
  • unity2020打包webGL时卡进程问题
  • 云原生架构相关技术_3.无服务器技术
  • Leetcode:Z 字形变换
  • Python 3 判断文件是否存在
  • (深度学习记录)第TR3周:Transformer 算法详解
  • 谷神前端组件增强:自定义列
  • 31-ESP32-S3-WIFI篇-02 Event Group (事件标记组)
  • 构建企业级AI私有知识库
  • C语言王国——杨氏矩阵
  • 陪玩小程序都需要怎么做?
  • postgressql——子事务可见性判断 性能问题(8)
  • 20240531在飞凌的OK3588-C开发板上跑原厂的Buildroot测试USB摄像头
  • 从0开始学统计-什么是回归?
  • Element-ui使用上传时弹框选择文件类型
  • 原生小程序一键获取手机号
  • ARM虚拟机安装OMV
  • 【协议开发系列】梳理关于TCP和UDP两种协议的区别和使用场景
  • vue blob实现自定义多sheet数据导出到excel文件