[英]R ggplot2: Title and legend in one line
How do I align the title and legend in one line in ggplot2 2.2.0
? 如何在
ggplot2 2.2.0
中将标题和图例对齐在一行?
library(ggplot2)
library(dplyr)
library(tidyr)
dfr <- data.frame(x=factor(1:20),y1=runif(n=20)) %>%
mutate(y2=1-y1) %>%
gather(variable,value,-x)
ggplot(dfr,aes(x=x,y=value,fill=variable))+
geom_bar(stat="identity")+
labs(title="Badass title")+
theme(legend.position="top",
legend.justification="right")
Changing the lineheight
and/or vjust
as title property doesn't seem to do anything. 将
lineheight
和/或vjust
更改为title属性似乎没有做任何事情。
ggplot(dfr,aes(x=x,y=value,fill=variable))+
geom_bar(stat="identity")+
labs(title="Badass title")+
theme(legend.position="top",
legend.justification="right",
plot.title = element_text(lineheight=-5,vjust=0))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.