Home   Publications   Resources   My CV   Contact   RSSRSS

Changing Axis Values in R Plot

March 16, 2013 by Daniel Marcelino | Filed under Tutorials.

A colleague asked me for how one can change axis attributes in a basic plot. Plotting anything in R is really, really easy. It is enough typing plot(x, y). In general, plot functions are nicely pre-cooked, so hardly one needs to change anything. But if changes in the default attributes are needed, it is possible to achieve by including extra information to the basic syntax, like as: plot(x, y, yaxs = "i"). Actually, we can change everything in the basic chart. To see how, just take a time yourself and type: ?plot, then you can unfold several specific topics as: ?axis etc. You will see how wealthy are the resources available.

In the plot below, I plotted 6 scatterplots in only one object specially to show the chart manipulation. In the first scatterplot: top-left-hand I show the result of a default plot. In the middle plot of the same row, there is a version without the two axes. I setup this by passing the argument: axis=FALSE in the command line. The third plot, in the top-right-hand, I added the x-axis just as it is. That is, without any manipulation of the numerical scale. In the fouth plot at bottom-left-hand, I added the y-axis to the plot, but still without manipulation. Finally, in the middle plot in the same second row, I added a y-axis where I manipulated not only the sacle by setting up my own “yticks” values, but also the colour and the position of the numbers in the axis. In the last plot, I also manipulated the scale of the x-axis to range from 0 to 3 by .5. The syntax of this example is shown bellow the chart.

plots


Tags: , ,

One Response to “Changing Axis Values in R Plot”

  1. Anonymous says:

    Great, thanks for sharing this blog article.Really looking forward to read more.

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax