ggplot2直方图图例太大了

sla*_*tir 1 r legend histogram ggplot2 stackedbarseries

我很满意我得到的结果R.我的大多数叠加直方图都看起来很好,例如

在此输入图像描述

在此输入图像描述

但是,我有一些在传奇中有这么多类别的传说中,传说中的情节很多,例如

在此输入图像描述

我怎样才能解决这个问题?

这是我的plot.r,我在命令行上调用这个

RScript plot.r foo.dat foo.png 1600 800
Run Code Online (Sandbox Code Playgroud)

foo.dat

account,operation,call_count,day
cal3510,foo-method,1,2016-10-01
cra4617,foo-method,1,2016-10-03
cus4404,foo-method,1,2016-10-03
hin4510,foo-method,1,2016-10-03
mas4484,foo-method,1,2016-10-04
...
Run Code Online (Sandbox Code Playgroud)

整个foo.dat:http://pastebin.com/xnJtJSrU

plot.r

library(ggplot2)
library(scales)

args<-commandArgs(TRUE)

filename<-args[1]
png_filename<-args[2]

wide<-as.numeric(args[3])
high<-as.numeric(args[4])

print(wide)
print(high)

print(filename)
print(png_filename)

dat = read.csv(filename)

dat$account = as.character(dat$account)
dat$operation = as.character(dat$operation)
dat$call_count = as.integer(dat$call_count)
dat$day = as.Date(dat$day)

png(png_filename,width=wide,height=high)

p <- ggplot(dat, aes(x=day, y=call_count, fill=account))
p <- p + geom_histogram(stat="identity")
p <- p + scale_x_date(labels=date_format("%b-%Y"), limits=as.Date(c('2016-10-01','2017-01-01')))

print(p)

dev.off()
Run Code Online (Sandbox Code Playgroud)

sla*_*tir 8

来自@PierreLafortune的回答

使用:

p <- p + theme(legend.position="bottom")
p <- p + guides(fill=guide_legend(nrow=5, byrow=TRUE))
Run Code Online (Sandbox Code Playgroud)

大有改善