简体   繁体   English

间隔绘制x轴值

[英]Plotting x-axis values at intervals

I will like to plot some data, with the x-axis data plotted at intervals 我想绘制一些数据,并以间隔绘制x轴数据

X: X:

50.0000
100.5467
689.7431
1559.8025
1000.9365
10.9095

Y: Y:

-0.0596123270783229
 0.644158691971081
-0.433854284204926
-0.365746109442603
 0.566685929975495
 0.398462720589891 

Function: 功能:

plotM<- function( dat, m ) {
  plot(data$X, data$Y,
       log="x", pch=20, cex=0.7,
       col = ifelse( data$Y < m, "red", "black" ), 
       xlab = "Y", ylab = expression(Log[2]~Fold~Change))
}

Function call: 函数调用:

plotM(dat, .05) 

How can I plot the data with the following sequence in x-axis: 如何在x轴上按以下顺序绘制数据:

10, 100, 1000, 2000

Thanks 谢谢

You need to create a plot with no axes then add them manually. 您需要创建一个没有轴的图,然后手动添加它们。

Using some example data 使用一些示例数据

x = 10^(0:3)
y = 0:3

We plot x and y and specify no axis are to be plotted: 我们绘制xy并指定不绘制轴:

plot(x, y, log="x", axes=FALSE, frame=TRUE)

Then add on the x and y axis manually 然后手动在x和y轴上添加

## See ?axis for more details
axis(1, 10^(0:3), 10^(0:3))
axis(2)

Alternatively, we can be a bit more fancy with the axis labels to get 或者,我们可以更喜欢轴标签来获得

axis(1, 10^(0:3),  c(expression(10^0), 
                     expression(10^1), 
                     expression(10^2), 
                     expression(10^3)))

to get 要得到

在此处输入图片说明

Try this... I have used ggplot2, much used graphical package of R. 试试这个...我用过ggplot2,它是R的常用图形包。

It will create x axis on log scale using ggplot.. 它将使用ggplot在对数刻度上创建x轴。

ggplot(data = data) + geom_line(aes(x = x, y = y)) + scale_x_log10()

This is how results will look like... 结果就是这样...

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM