1

ggplot を使用して、実験的なインストールで利用可能なデータを示すプロットを作成しています。私の問題は、y 軸が混雑しすぎることです。そのため、1 つおきの目盛りを長くして、軸ラベルに大きなフォントを使用できるようにしたいと考えています。

私の目標は、フィールド インストール数と測定時の年齢をプロットし、利用可能なすべてのデータを表示し、最初の測定時の年齢で並べ替えることです。擬似データを使用した例を次に示します。y 軸上のインストールのプロット順序は、最初の測定時の年齢に基づいていることに注意してください。

# create data frame of fake values
set.seed(1)
plots <- data.frame(installation=rep(sample(seq(1,100,1), 10), each=10),
                    age=as.vector(replicate(10, sample(seq(1,50,1), 10))))

# set up installations as factor, sorted by age at first measurement
odr <- ddply(plots, .(installation), summarize, youngest = min(age))
odr <- odr[order(odr$youngest),]
plots$installation <- factor(plots$installation, levels=rev(as.numeric(as.character(odr$installation))))
rm(odr)

# plot the available data
ggplot(plots, aes(installation, age)) + 
  geom_point() +
  coord_flip() 

ここに画像の説明を入力

実際には約 60 のインスタレーションとそれぞれのラベルを持っているので、混み合っています。1 つおきの y 軸の目盛りをずらして少し長くすることで、ラベルに大きなフォントを使用できます。これは私が答えを得ることを望んでいる質問です。

偶数要素と奇数要素を別々にプロットしてみました。これにより、それぞれの軸マークをいじることができましたが、順序付けがうまくいかず、理由がわかりません。軸の目盛り効果を得る方法がある場合、私はこのアプローチと結婚していない別の方法を求めています。

# break up the data frame into odd and even factors
odds <- plots[as.numeric(plots$installation) %% 2 != 0,]
evens <- plots[as.numeric(plots$installation) %% 2 == 0,]

# try and plot odds and evens seperately
ggplot(odds, aes(installation, age)) + 
  geom_point() +
  coord_flip() +
  geom_point(data = evens, aes(installation, age))

ここに画像の説明を入力

4

2 に答える 2