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

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.

主站蜘蛛池模板: 太谷县| 平远县| 阳新县| 樟树市| 浠水县| 神池县| 红桥区| 芒康县| 沾化县| 汨罗市| 遂平县| 福海县| 泸西县| 德令哈市| 玉溪市| 和田县| 榆林市| 巫山县| 林西县| 闻喜县| 赫章县| 靖安县| 方山县| 阿拉善左旗| 彭水| 巍山| 拜泉县| 克拉玛依市| 新巴尔虎左旗| 保山市| 泽库县| 五大连池市| 吴忠市| 清丰县| 阿拉善盟| 东阿县| 龙游县| 巴马| 富宁县| 壶关县| 龙陵县|