r - R中混合多个图形的轴标题对齐
问题描述
我正在使用ggplot2
包来制作我的图表。我有 2 个图表,我plot_grid()
从cowplot
包中混合使用。
library(ggplot2)
library(cowplot)
x1 <- c(52.67, 46.80, 41.74, 40.45)
y1 <- c(1.726219351, 1.842421805, 1.790801758, 1.449997494)
x2 <- c(51.07, 65.97, 61.01, 49.25)
y2 <- c(5.39765063, 0.215293169, 0.694595893, 1.501089083)
DF <- data.frame(x1, y1, x2, y2)
p1 <- ggplot(DF, aes(x1, y1)) +
geom_point() +
theme(aspect.ratio = 1)
p2 <- ggplot(DF, aes(x2, y2)) +
geom_point() +
theme(aspect.ratio = 1)
plot_grid(p1, p2)
plot_grid(p1, p2, align = "hv")
第二个图(p2
_ 但是,y 轴标签与原始绘图 ( ) 大小(图像中的蓝线)保持在同一位置。有没有办法让标签靠近 y 轴作为原始图?p1
align
cowplot
p2
解决方案
具有固定轴比的图形对齐可能很困难。在任何情况下,如果你使用这个axis
参数除了align
事情之外。有关更多详细信息,请参见此处:https ://wilkelab.org/cowplot/articles/aligning_plots.html
library(ggplot2)
library(cowplot)
#>
#> ********************************************************
#> Note: As of version 1.0.0, cowplot does not change the
#> default ggplot2 theme anymore. To recover the previous
#> behavior, execute:
#> theme_set(theme_cowplot())
#> ********************************************************
x1 <- c(52.67, 46.80, 41.74, 40.45)
y1 <- c(1.726219351, 1.842421805, 1.790801758, 1.449997494)
x2 <- c(51.07, 65.97, 61.01, 49.25)
y2 <- c(5.39765063, 0.215293169, 0.694595893, 1.501089083)
DF <- data.frame(x1, y1, x2, y2)
p1 <- ggplot(DF, aes(x1, y1)) +
geom_point() +
theme(aspect.ratio = 1)
p2 <- ggplot(DF, aes(x2, y2)) +
geom_point() +
theme(aspect.ratio = 1)
plot_grid(p1, p2, align = "hv", axis = "tbrl")
由reprex 包(v0.3.0)于 2019 年 7 月 26 日创建
推荐阅读
- javascript - 异步函数 Javascript 中的 Cookie
- php - 使用elementor表单更新mysql中的表
- excel - Excel VBA - 对于每个循环备选方案
- apache-spark - org.apache.spark.SparkException:作业因 pyspark 中的阶段失败而中止
- keycloak - Keycloak 不会重定向到 https
- javascript - 使用 nightwatchjs 定位并检查脚本(在网页内)是否正确
- powerbi - 尝试使用 PowerBI 显示 Azure 流分析的窗口日期
- java - Android Firebase 身份验证,无法访问调试中可见的用户 Twitter 数据
- python - 如何将 Panda 列中相等的值移动到新列
- java - 排除依赖项无助于修复“包 org.w3c.dom 可以从多个模块访问:
, java.xml"