簡體   English   中英

R繪圖,更改繪圖軸的值的比例

[英]R plot, change scale of values for plot axis

我正在用R做圖,堆積條和軸2的代碼很簡單,這是線和軸4的代碼:

在此處輸入圖片說明

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),

在此處輸入圖片說明

我如何縮放“ 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:最后的情節:

在此處輸入圖片說明

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()

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM