Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stop ggplot2 from dropping data points outside of axis limits?

Tags:

If I make a line plot (a time series, for example) and set my axis limits, I want the line to continue off the plot when points are outside of the axis limits, and then come back into the plot for the next point that is within the axis limits. Right now, it seems that ggplot2 will just drop the points completely and give me a an "Error:" message.

like image 611
khoda Avatar asked Oct 25 '11 16:10

khoda


People also ask

How do I stop ggplot from scientific notation?

The scale_x_continuous() and scale_y_continuous() methods can be used to disable scientific notation and convert scientific labels to discrete form.

What does YLIM do?

ylim( limits ) sets the y-axis limits for the current axes or chart. Specify limits as a two-element vector of the form [ymin ymax] , where ymax is greater than ymin . ylim( limitmethod ) specifies the limit method MATLAB® uses for automatic limit selection.

What is scaling in ggplot2?

Scales in ggplot2 control the mapping from data to aesthetics. They take your data and turn it into something that you can see, like size, colour, position or shape. They also provide the tools that let you interpret the plot: the axes and legends.

How do I center Ggtitle?

The default ggplot title alignment is not centered. It is on the left. It's possible to put the title in the middle of the chart by specifying the argument hjust = 0.5 in the function element_text() : p + theme(plot. title = element_text(hjust = 0.5)) .


1 Answers

If you limit your axes by reducing the axis scale (scale_x_continuous(limits=...)), then that is the expected behavior. By adjusting the scale, you are defining what data should be part of the plot. If you want to use all the data, but just zoom in on a particular region of the axes, you want to use coord_cartesian(xlim=..., ylim=...) instead.

like image 178
Brian Diggs Avatar answered Oct 08 '22 17:10

Brian Diggs