使用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)更多推荐
发布评论