官术网_书友最值得收藏!

Formatting log axes

In scientific analysis, we often need to represent data on a logarithmic scale. In this recipe, we will see how we can do this easily in R.

Getting ready

All you need to try out in this recipe is to run R and type the recipe in the command prompt. You can also choose to save the recipe as a script so that you can use it again later on.

How to do it...

The simplest way to create an axis logarithmic is to use the log argument in the plot() command:

plot(10^c(1:5),log="y",type="b")

How it works...

The log argument takes character values, specifying which axes should be logarithmic: x for the x-axis only, y for the y-axis only, and xy or yx for both axes.

There's more...

We can also set scales to be logarithmic by setting the xlog and ylog arguments to TRUE with the par() command. This can be handy if we wish to have the same setting for multiple plots as par() applies the settings to all subsequent plots on the same device.

Note that R will not create the plot if our data contains zero or negative values.

主站蜘蛛池模板: 县级市| 苏尼特左旗| 林芝县| 邢台市| 阿尔山市| 东明县| 武汉市| 宜城市| 湖南省| 武宁县| 鸡东县| 炉霍县| 秭归县| 原阳县| 平顶山市| 怀远县| 罗甸县| 铁力市| 出国| 砚山县| 湖州市| 镇原县| 衢州市| 大新县| 巴马| 通榆县| 马山县| 顺义区| 灵璧县| 六盘水市| 织金县| 平原县| 威远县| 大荔县| 太白县| 舟曲县| 平安县| 石河子市| 明星| 平顺县| 枣强县|