首页 > 解决方案 > 在gglot r中缩放x轴上刻度之间的距离

问题描述

我有一个这样的图表。我对范围(-3.5,0.5)之间的微小变化感兴趣,但是,它只占据了 x 轴的一小部分,因此很难解释。

我尝试使用转换来记录比例以获得更好的可视化,但是,它显然不适用于负值。

那么有没有什么方法可以扩大这个区域,让图表看起来更好看呢?

代码:

ggplot() + geom_line(data = Final_diction, aes(x = Final_diction[,1], y 
= Final_diction[,4])) +
xlim(-3.5,20) +
geom_vline(xintercept=c(-0.5,0.5), linetype="dashed", color = "red") +
geom_vline(xintercept=c(-0.25,0.25), linetype="dashed", color = "blue") +
theme_bw() +
theme(axis.title = element_text(size = 20)) +
theme(axis.text = element_text(size = 18))

在此处输入图像描述

标签: rggplot2

解决方案


像这样的东西

library(ggforce)
library(ggolot2)
ggplot(mtcars, aes(x=mpg, y=disp, group=1)) +
  geom_line() + facet_zoom(xlim = c(15, 20))

推荐阅读