简体   繁体   English

如何在ggplot2包中自定义x轴?

[英]How to get customize the x-axis in ggplot2 package?

I am currently using the ggplot2 package to plot a quantity by each year and I want to make it so that only every other year shows up in the x-axis instead of every year, like it currently is. 目前,我正在使用ggplot2软件包按年绘制数量,并且希望将其绘制为仅每隔一年在x轴上显示一次,而不是像现在这样显示每年。 So how would I go about doing this in the ggplot2 package. 因此,我将如何在ggplot2软件包中执行此ggplot2

I am not sure how to show plots in stack overflow but my current plot has all the years from 1996 to 2011 right next to each other, but I only want to show every other year from 1996 so that all the tick marks are more spread apart from each other. 我不确定如何显示堆栈溢出的图,但是我当前的图显示1996年到2011年之间的所有年份彼此相邻,但是我只想显示1996年以后的每一年,以便所有刻度线都更分散彼此。

You should include a relevant example with code in your question. 您应该在问题中包含代码的相关示例。 However, making a few assumptions from your description, I'd guess that you might try using the scales package and including the following 但是,根据您的描述做出一些假设,我想您可能会尝试使用scales软件包,其中包括以下内容

library(scales)
scale_x_date(labels=date_format("%Y"), breaks=date_breaks("2 year")) 

with your ggplot statements. 与您的ggplot语句。

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

相关问题 如何在ggplot2中使用annotation_custom自定义x轴 - How to customize x-axis with annotation_custom in ggplot2 ggplot2:通过在某些标签上添加星号来自定义x轴 - ggplot2: customize x-axis by adding an asterisk to some of the labels 自定义ggplot2中的x轴刻度标签 - Customize x-axis tick labels in ggplot2 如何自定义 x 轴上分类变量的每个级别的保留宽度 [ggplot2] - How to customize the reserved width for each level of a categorical variable on x-axis [ggplot2] 如何在 R 中的 ggplot2 中自定义并将离散时间步添加到时间序列中的 x 轴 plot? - How to customize and add discrete time steps to x-axis in time series plot in ggplot2 in R? 如何在 ggplot2 中让 x 轴在零处截取 y 轴 - How to get the x-axis to intercept the y-axis at zero in ggplot2 如何使用ggplot2包将X轴上的2个分类变量和两个连续变量绘制为“填充”? - How to plot 2 categorical variables on X-axis and two continuous variables as “fill” using ggplot2 package? 如何在ggplot2中获取x轴的正数和负数并重新调整R中的y轴? - How to get both positive and negative number for x-axis in ggplot2 and rescale the y-axis in R? 如何用文本和上标ggplot2编写x轴标题 - How to write x-axis title with text and superscript ggplot2 ggplot2如何将行绘制到多个x轴数据点 - ggplot2 how to plot rows to multiple x-axis datapoints
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM