R绘图,改变绘图轴的值的比例

时间:2015-02-11 10:10:27

标签: r plot

我正在用R做绘图,堆叠条和轴2的代码很简单,这里是行和轴4的代码:

enter image description here

lines(y, 
    theLineValues,     
    type    = "o", 
    pch     = 20,
    lwd     = 2, 
    cex     = 1.2, 
    lty     = 1, 
    col     ="forestgreen")

axis(4, 
    at      = getYaxis(0,1,0.01, 3),    # function to get 3 values for axis
    labels  = getYaxis(0,1,0.01, 3),
    col.axis= "forestgreen", 
    las     = 1,
    cex.axis= 0.7,
    col     = "forestgreen",
    line    = 0)

然后我发现最小值和最大值:0.46,0.68,并且想要将它们用作轴,因此可以更明显地看到线的变化(红线)。

labels  = getYaxis(min(theLineValues),max(theLineValues),0.01,3),

enter image description here

我如何缩放'theLineValues'来做到这一点?

感谢。

=============================================== ======================= 更新1:'y'的代码:

y <- barplot(
    combinedvalues,     # it's list of 3-combined values.
    col     = c("slategray1","darkseagreen1","moccasin"),
    beside  = FALSE,
    border = "grey80",
    las     = 1,
    cex.axis= 1.0,
    ann     = FALSE,
    ylim    = c(0,1),
    yaxt    = "n")

=============================================== ======================= 更新2:组合值:

这些值在.csv文件中,并使用以下内容获取'组合值'并将其传递给'y':

rbind(csv$frame0,csv$frame1,csv$frame2)
# frame0+frame1+frame2 shoud be 1, theLineValues were calculated by some formulas. 

csv文件:

frame0          frame1          frame2          theLineValues
------------------------------------------------------------
0.4460203874    0.2271394791    0.3268401336    0.4674583872
0.4473756948    0.2084173711    0.3442069341    0.4796977238
0.5296042291    0.1570493286    0.3133464423    0.570317484
0.5255498752    0.1234146373    0.3510354875    0.6095475721
0.5405768621    0.119299957     0.3401231808    0.6251561825
0.5657840709    0.0916650587    0.3425508703    0.6896446583
0.4826617968    0.0877739789    0.4295642243    0.6610089801
0.3588171226    0.122977733     0.5182051444    0.606129318
0.2608499204    0.1705417922    0.5686082874    0.595971676
0.2111782825    0.2040231107    0.5847986067    0.6057364576
0.1731616573    0.240909341     0.5859290016    0.6153720603

感谢。

=============================================== ======================= 更新3:最终情节:

enter image description here

1 个答案:

答案 0 :(得分:1)

Frames.txt基于三个框架列。

数据

frames <- read.table("/your-path/frames.txt",header=T,na.string="NA")

theLineValues<-c(0.4674583872, 0.4796977238, 0.570317484, 0.6095475721, 0.6251561825, 0.6896446583, 0.6610089801, 0.606129318, 0.595971676, 0.6057364576, 0.6153720603)

<强>剧情

barplot(t(frames), , col = c("slategray1","darkseagreen1","moccasin"))
axis(2, ylim=c(0,1))
mtext("barplot values", side=2, line=2)
box()

par(new=TRUE)
plot(theLineValues, type = "l", pch = 20, xlab="", ylab="", col = "forestgreen", lwd=2, ylim=c(min(theLineValues), max(theLineValues)), axes=FALSE)
axis(4, ylim=c(min(theLineValues), max(theLineValues)))
mtext("lineValues", side=4, line=0.2)
box()

enter image description here