0

このようなデータがあります。

ここに私の現在のコード

library(ggplot2)
library(RColorBrewer)
pal <- c(brewer.pal(8,"Dark2"),brewer.pal(12,"Paired"));
dat<-read.table("http://dpaste.com/1051194/plain/",header=TRUE)
dat.sub <- data.frame(dat$Function,dat$Freq)
ggplot(dat.sub,aes(dat.Freq,color=dat.Function),shape=dat.Function)+ stat_density(geom="path",position="identity",size=0.5)

以下のような図を生成します。 ここに画像の説明を入力

凡例テキストの長さにより、メイン プロットが圧迫されることに注意してください。図が正常に表示され、凡例も完全に表示されるようにするには、これに対処する最善の方法は何ですか?

4

1 に答える 1

5

1 つの可能性は、プロットの下に凡例を配置してから、2 つの列にラベルを配置することです。

ggplot(dat.sub,aes(dat.Freq,color=dat.Function),shape=dat.Function)+ 
  stat_density(geom="path",position="identity",size=0.5)+
  theme(legend.position="bottom",legend.direction="vertical")+
  guides(color=guide_legend(ncol=2))

ここに画像の説明を入力

于 2013-04-08T14:37:59.317 に答える