r - 如何消除ggplot方面的死区?
问题描述
如何消除下方刻面面板上的死区?我希望在面板“A”上消除 10-12个月的死空间 ,从面板“B”上消除1-9 个月的死空间。
我不想使用手动方法,因为我有很多经常更改的数据。我还需要面板正确地相互缩放。面板“A”应该是面板“B”长度的三倍,因为它的 x 轴包含九个值,而面板“B”的 x 轴只包含三个值。
理想情况下,面板“B”应该看起来像面板“A”被取消的延续。
library(tidyverse)
library(ggQC)
# Create the data frame
set.seed(5555)
Golden_Egg_df <- data.frame(month = 1:12,
egg_diameter = rnorm(n = 12, mean = 1.5, sd = 0.2),
group = c(rep("A", 9), rep("B", 3)))
#> month egg_diameter group
#> 1 1.346167 A
#> 2 1.410460 A
#> 3 1.219141 A
#> 4 1.578410 A
#> 5 1.648865 A
#> 6 1.207796 A
#> 7 1.490460 A
#> 8 1.330943 A
#> 9 1.431585 A
#> 10 1.433876 B
#> 11 1.673110 B
#> 12 1.632368 B
# Plot data frame on a control chart
XmR_Plot <- ggplot(Golden_Egg_df, aes(x = month, y = egg_diameter)) +
geom_point() + geom_line() +
stat_QC(method = "XmR") +
facet_grid(~group)
XmR_Plot
解决方案
我们可以使用space = "free"
参数facet_grid
XmR_Plot <- ggplot(Golden_Egg_df, aes(x = month, y = egg_diameter)) +
geom_point() + geom_line() +
stat_QC(method = "XmR") +
facet_grid(~group, scales = "free", space = "free") +
scale_x_continuous(breaks = 1:12,
labels = month.abb # delete this (and the comma in the line above) if you want numbers
)
XmR_Plot
推荐阅读
- python - 字典数据未在 Pandas DataFrame 中分成列
- java - com.fasterxml.jackson.databind.exc.InvalidDefinitionException:使用 lombok 时找不到类的序列化程序
- python - 如何拆分巨大的 CSV 文件?
- javascript - 传单地图未在我的 React CodeSandbox 中呈现
- python - 修改存储在数据框列表中的数据框
- android - 如何在 listView 中设置最终滚动的位置?
- sql-server - 是否可以检查 MS SQL Server 转储(.dat-binary,使用 bcp 导出)?
- amazon-web-services - Sumo Logic 和 Cloudwatch 日志不适用于查询源
- ssas - 使用 REST API 调用在 Azure 分析服务中创建对象
- python - 带有 if 语句的优先级方案(首先传递一个条件,然后将其余元素应用于第二个条件)