使用ggforce facet

编程入门 行业动态 更新时间:2024-10-28 12:25:04
使用ggforce facet_zoom操纵y轴刻度(Manipulate y-axis scale using ggforce facet_zoom)

我正在绘制一个时间序列,我想放大几个观察。 这可以使用ggforce包中的facet_zoom()来ggforce 。

library(dplyr) library(ggplot2) library(ggforce) library(stringr) airquality %>% mutate(month_day = seq(as.Date("2000/1/1"), by = "month", length.out = n())) %>% ggplot(aes(x = month_day, y = Temp)) + geom_line() + facet_zoom(x = month_day > "2010/1/1" & month_day < "2010/9/1")

结果情节:

但是,我想操纵下面板图的y轴上的比例,使其更小。 有没有办法做到这一点?

I am plotting a time series and I want to zoom on few observations. This can be done using facet_zoom() from ggforce package.

library(dplyr) library(ggplot2) library(ggforce) library(stringr) airquality %>% mutate(month_day = seq(as.Date("2000/1/1"), by = "month", length.out = n())) %>% ggplot(aes(x = month_day, y = Temp)) + geom_line() + facet_zoom(x = month_day > "2010/1/1" & month_day < "2010/9/1")

Resulting plot:

However, I would like to manipulate the scale on y-axis of the lower panel plot, making it smaller. Is there a way to do this?

最满意答案

使用xy代替x ,并将horizontal设置为TRUE以自动调整y轴:

airquality %>% mutate(month_day = seq(as.Date("2000/1/1"), by = "month", length.out = n())) %>% ggplot(aes(x = month_day, y = Temp)) + geom_line() + facet_zoom(xy = month_day > "2010/1/1" & month_day < "2010/9/1", horizontal = FALSE)

在此处输入图像描述

Use xy instead of x, and set horizontal to TRUE to auto fit the y-axis:

airquality %>% mutate(month_day = seq(as.Date("2000/1/1"), by = "month", length.out = n())) %>% ggplot(aes(x = month_day, y = Temp)) + geom_line() + facet_zoom(xy = month_day > "2010/1/1" & month_day < "2010/9/1", horizontal = FALSE)

enter image description here

更多推荐

本文发布于:2023-07-31 12:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1343787.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ggforce   facet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!