How to control plot axis major line densities in R?

by MichaelE   Last Updated January 04, 2018 17:26 PM

I need to be able to control how dense the axis lines are in my chart. I found one online example here that is the closest that I ever found.

Given the sample data:

y <- sample(10, 100, rep=T)
x <- rnorm(100)
plot(x,y)

gives me: enter image description here With the x and y axis more spacing than needed. but I can force the axis manually as listed on the site.

axis(1,at=seq(-2,3,.5))
axis(2,at=seq(0,10,.5))

Then I get this plot.

enter image description here

The view seems to change with zoom, but the x axis is messed up with -2 showing up a -220. This maybe from the small image, but it happens even when zoomed where all values are visible. The y axis is similar, but it also added unnecessary 0s for whole numbers. What would be better if both the x and y axis values were rotated 90 degrees so adding digits would not cause interference and make the font size smaller to make it fit. (I just noticed that the font size is always the same regardless of zoom) All automatically.

The biggest problem is that in the example I manually set the ranges, which is not something I can do in actual usage. I need some way to automatically set maximum and minimum density of the little ticks and tick labels. Maybe I want a number every 1, but a tick on the x axis every .1. I can use any comment or package if it can do this properly. Most importantly it should be automatic and also work with xts time series data with options for days hours and minutes as needed as dense as possible.

Update: If it helps, I use the plot or ggplot2 to plot many charts in a script and export them to a pdf file. The result is a huge image with 3 to 5 axis lines. This makes the chart very difficult to read accurately. It could fit 100 lines which would be much easier.

Tags : plot ggplot2


Related Questions


ggplot2 density-plot with discrete data

Updated December 17, 2017 18:26 PM

Change colors of raster plot in ggplot2

Updated April 06, 2015 20:11 PM

Display percentage by column on a stacked bar graph

Updated April 19, 2017 09:26 AM

Play 3d graphic on ggplot2

Updated May 06, 2017 09:26 AM