2015-08-19 105 views
0

在y標籤我有在Y軸上攝氏的曲線的確切華氏轉換Y軸攝氏:R plot。上與第二Y軸

plot(y=0:100,x=0:100, main="temperature",xlab="time",ylab="Celsius",type="l") 

如何可以繪製的相同的二級Y標尺,但與的單位,在y軸上以攝氏度顯示爲第二y軸上的華氏溫度。 T(°F)= T(℃)×9/5 + 32 我需要兩個y軸的標記的位置,以準確地對應,以使輔助y標籤顯示轉換後的值,是主y標籤上。

謝謝你的幫助。

+1

注:我們不使用攝氏度了,但攝氏度。 –

+0

的http://stackoverflow.com/questions/21375505/r-creating-graphs-with-two-y-axes – maj

+4

可能重複的可能的複製[I如何與2個不同的y軸繪製?](HTTP:/ /stackoverflow.com/questions/6142944/how-can-i-plot-with-2-different-y-axes) –

回答

2

在這惡劣的形式,你可以使用axis()

plot(y=0:100,x=0:100, main="temperature",xlab="time",ylab="Centigrate",type="l") 

axis(4, at=0:100, labels=0:100 * 9/5 + 32) 

您可以通過使用seq(0, 100, by=10)獲得較少的標籤。您還需要設置par(mar=)以符合您的軸標籤。

1

下面是一個例子與左右兩側漂亮的蜱。

set.seed(1) 
temp <- rnorm(10) * 10 + 10 # random temperatures 

par(mar=c(5.1, 5.1, 5.1, 5.1)) # extra margin space 
plot(temp, ylab="degrees C") 
ylim <- par("yaxp")[1:2] # get range of original y-axis 

# slope and offset coefficients to convert between degrees C and F 
slope <- 9/5 
offset <- 32 
alt.ax <- pretty(slope * ylim + offset) 
alt.at <- (alt.ax - offset)/slope 

axis(side=4, at=alt.at, labels=alt.ax, srt=90) 
mtext("degrees F", side=4, line=par("mgp")[1]) 

output