有没有办法让ggplot将图例置于顶部但位于标题下方?
作为一个例子......
..使用以下代码生成:
carrots<-list(Yield=c(345,226,74,559,288,194),
Field=c("A","B","C","D","E","F"),
Breed=rep(c("Long","Short"),each=3))
carrots<-data.frame(carrots)
ggplot(carrots,aes(y=Yield,x=Field,fill=Breed)) +
geom_bar() +
opts(title="Title",
legend.direction = "horizontal",
legend.position = "top") +
labs(fill="")
任何建议都会受到高度赞赏?
答案 0 :(得分:4)
修改忽略此信息。问题不再是问题。 但代码已更新,因此不再引发错误。
在等待下一个版本时,您可以在ggplot2中进行微调。例如:
ggplot(carrots, aes(y = Yield, x = Field, fill = Breed)) +
geom_bar(stat = "identity") +
theme(
plot.margin = unit(c(2, 1, 1, 1), "cm"),
plot.title = element_text(size = 30, face = "bold", colour = "blue", vjust = 7),
legend.direction = "horizontal",
legend.position = c(0.1, 1.05)) +
ggtitle("Title") +
labs(fill = "")