從ggplot 2.2.0開始,標題默認是左對齊的。爲了讓他們再次爲中心已經在這個崗位已經解釋:使用theme_bw在ggplot2中繪製標題
這在我的情況下完美的作品爲好,但不是如果我用theme_bw。
dat <- data.frame(
time = factor(c("Lunch","Dinner"), levels=c("Lunch","Dinner")),
total_bill = c(14.89, 17.23)
)
ggplot(data=dat, aes(x=time, y=total_bill, fill=time)) +
geom_bar(colour="black", fill="#DD8888", width=.8, stat="identity") +
guides(fill=FALSE) +
xlab("Time of day") + ylab("Total bill") +
ggtitle("Average bill for 2 people")+
theme(plot.title = element_text(hjust = 0.5))+
theme_bw()
我試圖傳遞的主題參數theme_bw()
theme_bw(plot.title = element_text(hjust = 0.5))
但did`t工作無論是。
任何想法?幫助深表感謝
是的,就是這樣。實際上很容易,但沒有看到它。謝謝! – HannesZ
Hi @HannesZ如果這解決了你的問題,請考慮通過點擊複選標記來接受它。這向更廣泛的社區表明,您已經找到了解決方案,併爲答覆者和您自己提供了一些聲譽。沒有義務這樣做。 – AntoineBic
對不起,我以爲我已經做到了。我接受得太快:) – HannesZ