2
如何在ggplot2 2.2.0
的一行中对齐标题和图例?R ggplot2:一行中的标题和图例
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")
改变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))
也许加上'主题(plot.title = element_text(保证金=保证金(0,0,0,0 ,“line”)),legend.box.margin = margin(-1,0,0,0,“line”))'? – lukeA