【问题标题】:R ggplot different colours in title labelR ggplot标题标签中的不同颜色
【发布时间】:2014-04-03 15:47:59
【问题描述】:

我可以在ggplot中绘制图表并添加标题:

library(ggplot2)
plot <- ggplot(PlantGrowth, aes(x=group, y=weight)) + geom_boxplot()
plot
plot <- plot+ ggtitle("red label\nblue label")
plot

但是如何改变标题的颜色,所以标题的第一部分是红色,第二部分是蓝色?

感谢您的帮助。

【问题讨论】:

标签: r ggplot2


【解决方案1】:

感谢old google groups page

print(plot, vp=viewport(height=0.8))
grid.text(0.5, unit(1,"npc") - unit(1,"line"), 
          label="Red text\n",
          gp=gpar(col="red"))
grid.text(0.5, unit(1,"npc") - unit(1,"line"), 
          label="\nBlue text",
          gp=gpar(col="blue"))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-25
    • 2021-02-07
    • 1970-01-01
    相关资源
    最近更新 更多