简体   繁体   English

如何在ggplot2中使y轴与x轴相交为0?

[英]How do I make the y-axis intersect the x-axis at 0 in ggplot2?

So when I make plots sometimes I see the y crossing x at some offset. 因此,当我制作情节时,我会看到y交叉x处于某个偏移处。 I generated this figure using: 我使用以下方法生成此图:

ggplot(data=d2,aes(y=log10(Nems+1),x=Time)) +
  geom_point(size=3,shape=1) +        
  geom_line(data=d2,aes(x=time_model,y=log10(value),group=variable,linetype=variable)) +
  ylim(0.001,2) + no_bg + draw_axis

I end up manually moving the y in Illustrator. 我最终在Illustrator中手动移动y。 Is there a way to just do it here? 有没有办法在这里做到这一点?

alt text http://img816.imageshack.us/img816/7633/testzh.png alt text http://img816.imageshack.us/img816/7633/testzh.png

Here is another solution: 这是另一个解决方案:

... + scale_x_continuous(expand=c(0,0))

See also this related question: Margin adjustments when using ggplot's geom_tile() 另请参阅此相关问题: 使用ggplot的geom_tile()时的边距调整

Try adding this to your plot: + coord_cartesian(xlim = c(0, 90)) 尝试将此添加到您的情节: + coord_cartesian(xlim = c(0, 90))

That should limit the x-axis to 0 through 90. 这应该将x轴限制为0到90。

You could also do + xlim(0, 90) , which has a similar effect - but also removes any data outside of its bounds from the dataset. 您也可以执行+ xlim(0, 90) ,它具有类似的效果 - 但也会从数据集中删除其边界之外的任何数据。 That can be problematic if you're trying to zoom in on features of geoms that should be calculated using the whole dataset (eg, smooths) because it recalculates those geoms based only on what's inside the limits. 如果你试图放大应该使用整个数据集计算的geom的特征(例如,smooths),这可能会有问题,因为它只根据限制内的内容重新计算这些geom。 coord_cartesian() calculates all the geoms from the full dataset, then limits the window to what you specify. coord_cartesian()从完整数据集计算所有geom,然后将窗口限制为您指定的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 R ggplot2:如何使x轴线不与y轴重叠? - R ggplot2: how to make x-axis lines not overlapping y-axis? 如何在 ggplot2 中在 x 轴上绘制两个向量,在 y 轴上绘制另一个向量 - How do you plot two vectors on x-axis and another on y-axis in ggplot2 如何在ggplot2中独立控制y轴刻度和x轴刻度? - How can I control y-axis ticks and x-axis ticks independently in ggplot2? 如何更改ggplot2中x和y轴的刻度标签,轴消失 - How do I change the tick labels of x and y-axis in ggplot2, axis disappearing 我可以在ggplot2中更改x轴与y轴相交的位置吗? - Can I change where the x-axis intersects the y-axis in ggplot2? 如何在不带ggplot2的情况下通过对R中的y轴进行排序来对x轴名称进行排序? - How to sort x-axis names by sorting y-axis in R without ggplot2? 如何根据 R ggplot2 中的 y 轴值重新排序 x 轴 - How to reorder x-axis based on y-axis values in R ggplot2 如何在 ggplot2 中让 x 轴在零处截取 y 轴 - How to get the x-axis to intercept the y-axis at zero in ggplot2 如何在ggplot2中获取x轴的正数和负数并重新调整R中的y轴? - How to get both positive and negative number for x-axis in ggplot2 and rescale the y-axis in R? 如何在 ggplot 上制作一个箱线图,其中我的 x 轴有两列,我的 y 轴有两列? - How to make a boxplot on ggplot with two columns for my x-axis and two columns for my y-axis?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM