【发布时间】:2015-02-11 10:10:27
【问题描述】:
我正在用 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:最终情节:
【问题讨论】:
-
如果是baseplot试试ylim=c(min(theLineValues), max(theLineValues))
-
顺便说一句。你能给出 y 的值吗?
-
y(堆积条形图)需要 yllime = c(0,1)
-
你有组合值的值吗?
-
我在下面的答案框中提供了一个解决方案,希望对您有所帮助!