3

プロットしたい単一の変数があります。ある場所の温度としましょう。横軸の「index = 1,2,3..」の代わりに、1,2,3 の代わりに別の列 (その場所の気温に対応) にある場所の名前が必要です。これを行う方法は?

このようなもの :

place1 32

place2 33

place3 43

place4 37

基本的に、列をプロットのラベルとして使用できるようにしたいと考えています。

4

1 に答える 1

3

データが次のとおりであると仮定します。

temp <- data.frame(temperature = c(32,33,43,37), 
                   place = paste("Place", 1:4))

あれは:

  temperature   place
1          32 Place 1
2          33 Place 2
3          43 Place 3
4          37 Place 4

以下を使用できます。

# Create a scatterplot, with an hidden x axis
plot(temp$temperature, pch=20, ylim=c(0, 50), 
     xaxt="n", xlab="Place", ylab="Temperature")
# Plot the axis separately
axis(1, at=1:4, labels=temp$place)

または、バープロットが必要な場合

barplot(temp$temperature, names.arg=rownames(temp$place))
于 2013-10-13T12:23:22.307 に答える