11

有没有办法让 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="") 

任何建议将不胜感激?

4

1 回答 1

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 = "") 
于 2012-04-23T21:49:27.983 回答