2016-01-23 184 views
0

一般來說,當我們繪圖時,繪圖的底部(從左到右)和左側(從底部到頂部)的x軸。
例如,在R-編程我有這樣的代碼:如何繪製在R編程中倒置的頂部和Y軸上的X軸?

t <- seq(0,1,0.2)  # need t values in top x axis 
plot(t,t^2,type="l") # need t^2 values in inverted y-axis 

現在,如果我們想的情節,使得x軸之上(左到右)和y軸反向(上到底部)。
我們如何才能在R編程中實現這樣的壯舉? 我搜索以下計算器中的鏈接,但他們不能滿足我的要求:
How to invert the y-axis on a plot

Invert y-axis in barplot

回答

4

退房?axis

t <- seq(0,1,0.2) 
plot(t,t,type="l", xaxt = 'n', yaxt = 'n') 
lines(t,t^2,col="green") 
lines(t,t^3,col="blue") 
axis(3) 
axis(2, at = pretty(t), labels = rev(pretty(t))) 

enter image description here

我不知道爲什麼.0被放棄在y上,但你可以使用labels = format(rev(pretty(t)), digits = 1)一致性

編輯

扭轉整個小區軸的約,只是反轉的情節xlimylim,你不必擔心翻轉或否定你的數據:

t <- seq(0,1,0.2) 
plot(t,t,type="l", xaxt = 'n', yaxt = 'n', ylim = rev(range(t))) 
lines(t,t^2,col="green") 
lines(t,t^3,col="blue") 
axis(3) 
axis(2, at = pretty(t), labels = format(pretty(t), digits = 1), las = 1) 

enter image description here

+0

如果我們反轉y軸上的值,曲線也應該改變,(它應該改變180度,然後翻轉左到右)。這裏只有y軸的值會改變,而不是曲線! –

+1

@BhishanPoudel你說反轉Y軸,我認爲你只是意味着Y軸不是整個情節,見編輯 – rawr

+0

哇,這是我想要的確切的東西,非常感謝@rawr –

相關問題