r - SAS SGPLOT 或 R ggplot2 - 为同一图生成单独的组件
问题描述
我想生成一个使用 SAS 或 R 附加的图。Y 轴的刻度为 1 到 100 作为连续值(中断为 21 到 49),X 轴有一个带有两个值的分类刻度。
我需要将 70% 的绘图区域分配给底部组件(即绘制 0-20 的值),然后将 30% 的绘图区域分配给顶部组件(即绘制 50 到 100 的值)。
有什么办法吗,我可以绘制 3 个不同的分量,即 0-20,中断 21-49,然后 50 到 100
解决方案
您可以使用 gridExtra 将它们拼凑在一起。并且可以使用 coord_cartesian() 或 grid.arrange() 中的高度规范调整缩放
library(tidyverse)
library(gridExtra)
data <- bind_cols(category = rep(c("Category1", "Category2"), 5),
value = c(sample(0:20,6), sample(50:100,4)),
group = c(1,1,2,2,3,3,4,4,5,5))
topgraph <- data %>%
ggplot(aes(x = category, y = value, group = group)) +
geom_line() +
labs(x = "") +
theme(axis.text.x = element_blank())+
coord_cartesian(ylim = c(50,100))
lowergraph <- data %>%
ggplot(aes(x = category, y = value, group = group)) +
geom_line() +
coord_cartesian(ylim = c(0,20))
grid.arrange(topgraph, lowergraph, heights = c(.3,.7))
推荐阅读
- javascript - 将 x 传递给函数并返回 y,反之亦然,无需任何条件语句
- javascript - Nextjs 增量静态生成,缓存清除
- reactjs - 是的,使用 Date 对象进行验证
- android - 为什么我无法安装适用于 Android API 30 的 SDK 平台?
- python - Flask + Celery 代理 redis 被覆盖
- c# - 有没有办法在 Visual Studio 2019 中更改 C# 项目的字符集?
- git - 停止 git 查看目录
- reactjs - router.push 在 next.js 中初始化 redux 状态是默认的吗?
- image-processing - gm convert:将 PDF 转换为 TIF 时 Postscript 委托失败
- nginx - HTTPS 中断 Socket.io/websocket 连接